angularjs - element.on($destroy) shows element is not defined in angular -


i trying cancel $interval event in directive while changing route or state of application. found code act in destroy event.

but returns element not defined. have inject service or directive in controller.

element.on('$destroy', function() {           console.log("cancelling interval");           $interval.cancel(promise);         }); 

error:

referenceerror: element not defined     @ new controller (http://localhost:port/src/controller.js     @ invoke (http://localhost:port/bower_components/angular/angular.js:4182:17)     @ object.instantiate (http://localhost:port/bower_components/angular/angular.js:4190:27)     @ http://localhost:port/bower_components/angular/angular.js:8453:28     @ $interpolate.compile (http://localhost:port/bower_components/angular-ui-router/release/angular-ui-router.js:3897:28)     @ invokelinkfn (http://localhost:port/bower_components/angular/angular.js:8217:9)     @ nodelinkfn (http://localhost:port/bower_components/angular/angular.js:7726:11)     @ compositelinkfn (http://localhost:port/bower_components/angular/angular.js:7075:13) 

thanks in advance code pretty long, posting snipper called. updated:

   (function ()    {     'use strict';     angular .module('app')    .controller('controller', controller);     controller.$inject = ['service', '$modal', '$interval', '$scope'];     function controller(service, $modal, $interval, $scope)    {       console.log("beginning");      var ctrl = this;      $scope.headername= "header name";      ctrl.selected = {};      setupdata();       var promise = $interval(setupdata, 1000000);      $scope.on('$destroy', function()      {       $interval.cancel(promise);       }); 

use $scope.$on('$destroy'..) , interval timer removed when new route initialized:

$scope.$on('$destroy', function() {       console.log("cancelling interval");       $interval.cancel(promise); }); 

within comments above attempt @ using $scope.on() incorrect angular internal events methods use $ prefix


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -