0
我試圖在範圍被銷燬時停止所有事件監聽器。
我得到這個錯誤:
TypeError: vm.$on is not a function;
無論vm.on(..)的作品
angular.module('app.layout')
.controller('DashboardController', DashboardController);
DashboardController.$inject = ['$interval','dataservice'];
function DashboardController($interval, dataservice) {
var vm = this;
vm.name = "DashboardController";
console.log('Init Dashboard Controller');
initEvents();
/*
...
*/
/////////////////////////////
function initEvents() {
vm.$on('$destroy', function() {
vm.stop();
console.log('DashboardController scope destroyed.');
})
}
'vm'是一個控制器,不是範圍。這是您需要注入'$ scope'服務的情況。 – Claies
我不是AngularJS的傢伙,但是$是$ scope方法... –