赞助

在AngularJS中,控制器没有生命周期方法,但是$scope对象有一些事件,可以模拟生命周期方法的行为。例如,$scope.$on('$destroy', function() {...})可以在控制器销毁时执行一些操作。

(function (angular) {
  'use strict';
  angular.module('iapp.dataSet').controller('editController', [
    '$rootScope',
    '$scope',
    'Ajax',
    'Urls',
    'growl',
    '$state',
    '$uibModal',
    '$timeout',
    function ($rootScope, $scope, Ajax, Urls, growl, $state, $uibModal, $timeout) {
      // This will run when the controller is instantiated
      console.log('Controller instantiated');

      // This will run when the controller is destroyed
      $scope.$on('$destroy', function() {
        console.log('Controller destroyed');
      });
    }
  ]);
})(window.angular);

  

posted on 2023-08-04 16:52  Tsunami黄嵩粟  阅读(10)  评论(0编辑  收藏  举报