Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set angular controller object property value from directive in child scope
    text
    copied!<p>I have have a directive inside an ng-repeater that should set a scope property. Please see the fiddle here: <a href="http://jsfiddle.net/paos/CSbRB/" rel="nofollow noreferrer">http://jsfiddle.net/paos/CSbRB/</a></p> <p>The problem is that the scope property is given as an attribute value like this:</p> <pre><code>&lt;button ng-update1="inputdata.title"&gt;click me&lt;/button&gt; </code></pre> <p>The directive is supposed to set the scope property inputdata.title to some string. This does not work:</p> <pre><code>app.directive('ngUpdate1', function() { return function(scope, element, attrs) { element.bind('click', function() { scope.$apply(function() { scope[ attrs.ngUpdate1 ] = "Button 1"; }); }); }; }); </code></pre> <p>However, assigning directly works:</p> <pre><code>scope["inputdata"]["title"] = "Button 1"; </code></pre> <p>Can you please tell me how I can set a scope property with . notation in its name from a directive?</p> <p>PS: The reason the fiddle is using a repeater is because it makes the directives be in child scopes. When they are in a child scope, you can't write to scope properties that are primitives. That's why I need an object property with "." in the name. See the long explanation here: <a href="https://stackoverflow.com/questions/14049480/what-are-the-nuances-of-scope-prototypal-prototypical-inheritance-in-angularjs/14049482#14049482">What are the nuances of scope prototypal / prototypical inheritance in AngularJS?</a></p> <p>Thank you</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload