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 -

node.js - Express and Redis - If session exists for this user, don't allow access -

excel - I can't get the attachement of the email PHP -