**轉自:作者:海底蒼鷹
地址: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**