1.在controller裏面利用$on或者$watchcode
bookControllers.controller('bookctrl_test', ['$scope', '$routeParams',
function($scope, $routeParams) {
$scope.$on('$viewContentLoaded', function() {
alert('1');
});
alert('2');
}]); it
bookControllers.controller('bookctrl_test1', ['$scope', '$routeParams',
function($scope, $routeParams) {
$scope.$watch('$viewContentLoaded', function() {
alert('1');
});
alert('2');
}]); io
2.利用data-ng-init
<div ng-controller="test">
<div data-ng-init="load()" ></div>
</div>
注意:data-ng-init在controller裏面纔會啓做用
bookControllers.controller('testInit', ['$scope', '$routeParams',
function($scope, $routeParams) {
$scope.load = function() {
alert('code here');
}
}]); function