angularjs – 侦听特定的$includeContentLoaded

前端之家收集整理的这篇文章主要介绍了angularjs – 侦听特定的$includeContentLoaded前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
每次更新ngInclude时都会触发$includeContentLoaded.

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

我想做的是,监听要加载的特定ngInclude,如回调:

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

这可能吗?

解决方法

你可以使用“onload”标签

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

并在范围函数中检查url,例如:

$scope.test = function(url){
    switch(url) {
        case '/path/to/iclude':
          /*******YOUR CODE***********/
          break;
    }
}

猜你在找的Angularjs相关文章