Retrieves a list of all events that can go through the angular scope. $$ listenerCount?

Inside the directive, I'm trying to get a list of all the event names that could potentially be captured by this area.

When observing a scope object, I see that there is a property $$listenersthat contains one function, and a property $$listenersCountthat actually contains a list of events that I defined belong to this area.

$$ listenerCount properties

I listen to most of these events in the child areas of the one that is being displayed, so I assume that this is a list of all the events that go through this area and not the events that the specific area listens to. I'm not sure what the numbers mean.

, , , .

- , , , ?

+4
1

$$ . @Blackhole, :

, Angular $ $$. , $ $$ .

- Angular Api

, $$ angular. . , . $scope. $On, , , , $$ listenerCount $parent, . - , . $$ , - , .


, ? Angular . , . , , angular ( . ). , , $ :

.config(function ($provide) {
    function wrap(oldFn, wrapFn) {
        return function () {
            return wrapFn.bind(this, oldFn)
                         .apply(this, arguments);
        }
    }

    $provide.decorator('$rootScope', function ($delegate) {
        var proto = Object.getPrototypeOf($delegate);

        proto.$on = wrap(proto.$on, function ($on, name, listener) {
            var deregister = $on.call(this, name, listener);
            console.log(this, name, listener, deregister);
            return deregister;
        });

        return $delegate;
    });
});

, $on. $Scope - this, name listener - , $on, deregister - . , ES5 Object.getPrototypeOf $on.

. console.log . , . plunker .

, $$, $$ . $, , API. , "Breaking Change" Angular , .

+3

Source: https://habr.com/ru/post/1543386/


All Articles