1.html中直接写(不建议)
<script type="text/javascript">
angular.element(window).bind('load', function() {
alert('1');
});
alert('2');
</script>
2.在controller里面利用$on或者$watch
(function(){"use strict";
angular.module('myApp')
.controller('testSth', ['$scope', function($scope){
$scope.$on('$viewContentLoaded', function(){
console.log('1');
});
console.log('2');
}]);
})();
//用$watch
(function(){"use strict";
angular.module('myApp')
.controller('testSth', ['$scope', function($scope){
$scope.$watch('$viewContentLoaded', function(){
console.log('1');
});
console.log('2');
}]);
})();
3.利用ng-init
<div ng-controller="testSth">
<div ng-init="loadSth()" ></div>
</div>
(function(){"use strict";
angular.module('myApp')
.controller('testSth', ['$scope', function($scope){
$scope.loadSth = function(){
console.log('i am loaded....')
}
}]);
})();
有朋自远方来...评论一下呗O(∩_∩)O