$scope, remove listener

8,168 views
Skip to first unread message

kostik.noir

unread,
Jan 15, 2013, 11:46:03 AM1/15/13
to ang...@googlegroups.com
Hi.
I'm new in angular.
There is $on method of scope which allow to add event listeners. But I'm not find way how to remove listener. Google was not help too.
Thanks.

Pawel Kozlowski

unread,
Jan 15, 2013, 1:26:54 PM1/15/13
to ang...@googlegroups.com
Hi!

There is no method for un-registering those listeners. Those will be
automatically destroyed when a corresponding scope is destroyed.
Please note that those listener are AngularJS-specific communication
bus and has nothing to do with DOM events and their listeners.

Cheers,
Pawel
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+u...@googlegroups.com.
> Visit this group at http://groups.google.com/group/angular?hl=en-US.
>
>



--
Question? Send a fiddle
(http://jsfiddle.net/pkozlowski_opensource/Q2NpJ/) or a plunk
(http://plnkr.co/)
Need help with jsFiddle? Check this:
http://pkozlowskios.wordpress.com/2012/08/12/using-jsfiddle-with-angularjs/

Looking for UI widget library for AngularJS? Here you go:
http://angular-ui.github.com/

Peter Bacon Darwin

unread,
Jan 15, 2013, 3:04:35 PM1/15/13
to ang...@googlegroups.com
Actually that is not strictly true.  In the docs - http://docs.angularjs.org/api/ng.$rootScope.Scope#$on - you can see that $on returns a "deregistration" function.  So you can do things like:

var removeListener = scope.$on('some-event', function handler(event) { ... });
...
removeListener();

And voila!  It is gone.

Pawel Kozlowski

unread,
Jan 15, 2013, 3:06:49 PM1/15/13
to ang...@googlegroups.com
Holly cow! Didn't know this (and didn't check!!!).
Thnx Peter!

Cheers,
Pawel

Константин Чёрный

unread,
Jan 16, 2013, 4:24:45 AM1/16/13
to ang...@googlegroups.com
Thanks

Jonathan Matthew Beck

unread,
Jul 9, 2014, 2:25:19 PM7/9/14
to ang...@googlegroups.com

Alex Ford

unread,
Jul 14, 2014, 11:19:59 AM7/14/14
to ang...@googlegroups.com
Thanks for this! :)
Reply all
Reply to author
Forward
0 new messages