ng-include监听载入完成的3种方式
标签:
JavaScript
针对单个引入文件设置
属性
<div ng-app="myApp" ng-controller="sitesCtrl"> <div data-ng-include="inner.html" ="includeInit()"></div><script type="text/javascript"> var app = angular.module('myApp', []); app.controller('sitesCtrl', function($scope) { $scope.includeInit = function(){ $scope.$broadcast('includeInit'); } $scope.$on('includeInit',function(){ console.log('include page finish.'); }); });</script>
针对单个引入文件设置
ng-init
事件
<div ng-app="myApp" ng-controller="sitesCtrl"> <div data-ng-include="inner.html" data-ng-init="includeInit()"></div><script type="text/javascript"> var app = angular.module('myApp', []); app.controller('sitesCtrl', function($scope) { $scope.includeInit = function(){ console.log('include page finish.'); } });</script>
通过
$rootScope
对象监听全局的$includeContentLoaded
事件
<div ng-app="myApp" ng-controller="sitesCtrl"> <div data-ng-include="inner.html"></div><script type="text/javascript"> var app = angular.module('myApp', []); app.run(['$rootScope',function($rootScope){ $rootScope.$on('$includeContentLoaded',function(){ console.log('include page finish.'); }) }]);</script>
作者:梁同学de自言自语
链接:https://www.jianshu.com/p/86211a0dad8c
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦