angular ngmodel - AngularJs Directive two way binding: How to preserve reference? -
I have a directive in which there is two types of bond with one attribute. I want to reassign the attribute in the link function. However, this reference breaks.
What is the correct way to do this?
& lt; Div ng-app = "zippy module" & gt; & Lt; Div ng-controller = "ctrl3" & gt; Title: & lt; Input ng-model = "title" & gt; & Lt; Div class = "zippy" zippy-title = "obj" & gt; {{Obj.a}} & lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; JavaScript function Ctrl3 ($ scope) {$ scope.obj = {a: "a", b: "b"}; } {Angular Module ('zippyModule', []). Directive ('zippy', function () {return: {title: '= zippyTitle'}, link: function (region, element, attrs) {title = A: "C", B: "D"}}}}; });
Try it out:
HTML & lt; Div ng-app = "zippy module" & gt; & Lt; Div ng-controller = "ctrl3" & gt; Title: & lt; Input ng-model = "title.a" & gt; & Lt; Div zippy = "zippy-title =" title "& gt; & Lt; / Div & gt; {{Title.a}} & lt; / Div & gt; & Lt; / Div & gt;
Comments
Post a Comment