在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);
右侧赞助一下 代码改变世界一块二块也是爱