Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the only case your directive needs to catch that event is to get some initial data <strong><em>depending on</em></strong> the <code>MyController</code> because if your directive is independent of the <code>MyController</code>, you don't need to catch that event, just initiate the directive independently.</p> <p>My solution is using $watch to get notified when the <strong><em>initial data</em></strong> from the <code>MyController</code> is ready.</p> <pre><code>app.controller('MyController', function($scope) { $scope.data = {}; //initialize the data, this data could be fetched from an ajax }); directiveModule.directive('MyDirective', ['MyService', function(MyService) { return { restrict: 'E', controller: ['$scope', function($scope) { $scope.$watch("data",function(newValue,OldValue,scope){ //do your work here when data is changed. }); }]}; }]; </code></pre> <p>In case you use isolate scope in your directive:</p> <pre><code>directiveModule.directive('MyDirective', ['MyService', function(MyService) { return { restrict: 'E', scope : { directiveData:"=", }, controller: ['$scope', function($scope) { $scope.$watch("directiveData",function(newValue,OldValue,scope){//watch on the directive scope property //do your work here when data is changed. }); }]}; }]; </code></pre> <p>Your html may look like this:</p> <pre><code>&lt;my-directive directive-data="data" /&gt; //bind isolate scope directive property with controller's scope property. </code></pre> <p>I think below questions are some similar cases like this: </p> <ul> <li><a href="https://stackoverflow.com/questions/19153430/angularjs-directive-not-able-to-access-isolate-scope-objects/19194393#19194393">AngularJS : Directive not able to access isolate scope objects</a></li> <li><a href="https://stackoverflow.com/questions/19142409/angular-directives-and-scope">AngularJS : directives and scope</a> </li> </ul>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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