Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularJS controller inheritance
    primarykey
    data
    text
    <p>AngularJS has a DOM based controller inheritance, as mentioned in the angular Docs.</p> <pre><code>&lt;div ng-controller="BaseController"&gt; &lt;p&gt;Base Controller Value: {{value}}&lt;/p&gt; &lt;button ng-click="updateValue()"&gt;Update In Base&lt;/button&gt; &lt;div ng-controller="DerivedController"&gt; &lt;p&gt;Derived Controller Value: {{value}}&lt;/p&gt; &lt;button ng-click="updateValue()"&gt;Update In Derived&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>The scope variable "value" is present only in the BaseController. Based on this, while changing the value at a method in BaseController or DerivedController, I want both the values need to be updated. But only the individual scope variable gets updated.</p> <p>Here is a fiddle demonstrating the same example: <a href="http://jsfiddle.net/6df6S/1/">http://jsfiddle.net/6df6S/1/</a></p> <p>How can changes at a level be made to propagate to the immediate child and immediate parent of the current scope.</p> <p>We can implement this by using </p> <blockquote> <p>$scope.$watch</p> </blockquote> <p>Is there any way to do this without using it or any such watchers?</p> <p>Edit 1:</p> <p>By using $scope.$watch here is what I meant</p> <pre><code>$scope.$watch("value", function () { $scope.$broadcast("childChangeListener"); //Downwards to all children scopes $scope.$emit("parentChangeListener"); //Upwards to all parent scopes }); </code></pre> <p>I was looking for ways in which the value would get updated across all scopes without using such a mechanism.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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