Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Incorrect behavior of deregistration function returned from $rootScope.$on when called twice #9666

Closed
@dmytroyarmak

Description

@dmytroyarmak

Hello,

I've notice that when you call deregistration function more than one time it decrease $$listenerCount each time.
https://github.com/angular/angular.js/blob/master/src/ng/rootScope.js#L1105-L1108

After $$listenerCount becomes zero $breadcast starts ignore this event and It cause that other listeners for the same event will not be called.
https://github.com/angular/angular.js/blob/master/src/ng/rootScope.js#L1219

Reproducing

Here is plunker and steps to reproduce:
http://plnkr.co/edit/bHtWlu?p=preview

We have page with two handlers that bound to "sampleEvent", 3 buttons that broadcasts and unbinds handlers, block with displayed $$listenerCount value.

  1. sampleEvent count equal 2
  2. Click "Emit simple event"
  3. Two alerts should appear
  4. Click "Unregister first handler"
  5. sampleEvent count equal 1
  6. Click "Emit simple event"
  7. One alert should appear
  8. Click "Unregister first handler" second time

Actual result:

There is no sampleEvent count and second handler is not triggered after broadcast 'sampleEvent'

Expected result:

sampleEvent should still be 1 and second handler should be triggered after broadcast 'sampleEvent'

I'm going to create pull request with fix for this bug after few minutes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions