1.在controller里面利用$on或者$watch

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');
}]);


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');
}
}]);

相关文章:

  • 2022-02-20
  • 2022-12-23
  • 2021-11-18
  • 2021-07-11
  • 2021-06-20
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-26
  • 2022-12-23
  • 2022-01-20
  • 2021-09-27
  • 2021-09-21
相关资源
相似解决方案