angularjs - Updated way to destroy a controller using the as and this syntax -


when using 'as' syntax , binding values on controller there new way destroy controller or should still using scope?

if declare controller in dom using 'as' syntax:

<section ng-controller="mycontroller mine">... 

and use 'this' syntax bind things controller instead of scope, how make sure controller destroyed?

myapp.controller('myapp', ['pubsub', function (pubsub) {   var mycontroller = this;   this.subject = ""   this.mytopic = pubsub.subscribe('mytopic', function(data) {     mycontroller.subject = data;    } } 

this create memory leak, controller not cleaned because pubsub holding reference controller.

is there way create destroy function controller, or still scope object listen destroy event?

myapp.controller('myapp', ['pubsub', '$scope', function (pubsub, $scope) { ... $scope.$on("$destroy", function() {   if (mycontroller.mytopic) {       mycontroller.mytopic.unsubcribe();       mycontroller.mytopic = null;   } }); 

using $scope special, such listen events, broadcasting, watching, emitting, etc, fine, when using controlleras syntax.


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 -