Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listen for a specific $includeContentLoaded

Tags:

angularjs

$includeContentLoaded is fired every time ngInclude is updated.

$scope.$on('$includeContentLoaded', function() {
  // Emitted every time the ngInclude content is reloaded
});

What I would like to do, is to listen for a specific ngInclude to be loaded, like a callback:

$scope.includePath('/path/to/iclude', function() {
  // Fired when the includePath ngInclude have finished loading
}

Is this possible?

like image 803
Alberto Avatar asked Aug 25 '14 08:08

Alberto


2 Answers

You can use "onload" tag:

<div ng-include="url" onload="test(url)">
</div> 

And check url in scope function, for example:

$scope.test = function(url){
    switch(url) {
        case '/path/to/iclude':
          /*******YOUR CODE***********/
          break;
    }
} 
like image 79
strelok2010 Avatar answered Sep 24 '22 20:09

strelok2010


in Angular 1.3, you have:

$rootScope.$on('$includeContentLoaded',function(event,url){
  if (url == 'YourDesiredPath') {
    // do something
  }
});
like image 26
Raghavendra Avatar answered Sep 25 '22 20:09

Raghavendra