angularjs - How can I inherit complex properties from the parent scope into my directive's isolated scope -


AngularJS (and related) After reviewing other stack overflow questions about separate scops within documentation and instructions, I Still, I am a little confused, why can not I make a bi-directional binding between the area of ​​the parents and the different scope, where the parent's property is an object and there is no specialty? Should I just use the desired property from the area? $ Parent? Thanks in advance for your help it looks wrong.

The relative is Bela.

HTML:

  & lt; Div ng-app = "myApp" & gt; & Lt; Div ng-controller = "myCtrl" & gt; & Lt; Div my-directive & gt; {{Test.name}} & lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt;   

Javascript:

  var myApp = angular.module ('myApp', []); MyApp.controller ('myCtrl', function ($ scope) {$ scope.test = {name: "name", value: "value"};}); MyApp.directive ("myDirective", function () {Return: true, restrict: 'A', scope: {test: '='}, template: '
; Div & gt
gt; {div> gt;} & lt; / div & gt; & lt; / div & gt; ', link: function (scope, element, etter) {console.log} "Scope .test = ["+ scope.test +"] "); Console.log ("scope. $ Parent.test = [" + scope. $ Parent.test.name + "]");}}}});

For instructions on using a separate scope, Features To specify which parent will have to separate the child's area to separate the opportunity properties, '=' provides two-way binding '@' "one-way wire" provided Does 'Amp;'

Provides the only expression.

To access your instructions (double-sided binding) on ​​the parent property property property, test , use this HTML:

 < Code> & lt; Div my-directive test = "test" & gt; & Lt; / Div & gt;   

It may be more instructive to use different names:

  & lt; Div my-directive somewhat-obj-prop = "test" & gt; & Lt; / Div & gt;   

then in your instructions:

  area: {localDirProp: '= someObjProp'}, template: '& lt; Div ... & gt; Value = {{LocalDirProp}} ... ',   

The isolated scops are not basically deprived of parents' territory, hence its parents Do not have access to properties (if '@' or '=' or '& amp;' is used). Using $ parent is still a way to reach the parent area, but not through prototype inheritance. Angular makes special $ parent property on this scope generally (i.e. best practice), it should not be used.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -