**转自:作者:海底苍鹰
地址:http://blog.51yip.com/jsjquery/1599.html**
1、html中直接写
<script type="text/javascript">
angular.element(window).bind('load', function() {
alert('1');
});
alert('2');
</script>
不建议,直接在模板里面,写js代码。
2、在controller里面利用
bookControllers.controller('bookctrl_test', ['$scope', '$routeParams',
function($scope, $routeParams) {
$scope.$on('$viewContentLoaded', function() {
alert('1');
});
alert('2');
}]);
bookControllers.controller('bookctrl_test1', ['$scope', '$routeParams',
function($scope, $routeParams) {
$scope.$watch('$viewContentLoaded', function() {
alert('1');
});
alert('2');
}]);
3、利用data-ng-init
<div ng-controller="test">
<div data-ng-init="load()" ></div>
</div>
<div ng-controller="test">
<div data-ng-init="load()" ></div>
</div>
注意:data-ng-init在controller里面才会启作用
**转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/jsjquery/1599.html**