angularjs - Angular isolated scope calling parent function -


I am playing with Kangaroo and am trying to know more about scope.

  var app = angular Module ('myapp', []); App.controller ('MainCtrl', function ($ scope) {$ scope.color = 'green'; $ scope.sayHello = function () {console.log ("Scope from parent");}}); App.directive ('helloWorld', function () {return: Restrict: 'AE', Replace: 'True', Scope: {color: '@colorAttr', sayHello: '& amp;;}, Template: & Lt; p style = "background-color: {{color}}"> Hello world ", link: function (scope, AMM, ethers) {scope.sayHello ();}};});  

I'm trying to call parent method (hello), but when I use a different scope it does not allow me I & amp; In separate scope, but I'm not sure I'm using it correctly.

  HTML & lt ;! DOCTYPE html & gt; & Lt; Html xmlns = "http://www.w3.org/1999/xhtml" xml: lang = "en" lang = "en" ng-app = "myapp" & gt; & Lt; Top & gt; & Lt; / Head & gt; & Lt; Body ng-controller = "MainCtrl" & gt; & Lt; Div ng-model = "color" /> & Lt; Hello-world color-atr = "{{color}}" & gt; Changed & lt; / Hello-world> & Lt; / Body & gt; & Lt; / Html & gt;  

I think you have to pass this kind of instructions to the law

  & lt; Hello-world color-entry = "{{color}}" - hello = "say hello ()" & gt; Changed & lt; / Hello-world>  Explain  

When you create a separate scope, the parent's scope is hidden from the instructions, so the written work is called halo (). Yet it is still accessible through the scope. $ Parent

The scope objectives in directive initialization establishes mapping between the properties / methods and the properties of the instruction, which in turn can be linked to the outer scope properties / methods.

The above code says that the link inside the link function is mapped to the parent area with the same name mapped with the function as stated in the attribute Hello-Hello.

Hope I was more clear at this time :)


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -