Elad Benda
Elad Benda

Reputation: 36674

child component doesn't get its parent's triggered event

I have followed this post

I have a parent component which contains (and it's called) :

$scope.$broadcast('searchNoFilter');

and a child component which contains (and it's called) :

$scope.$on('searchNoFilter', function(e) {
    self.search();
});

The parent triggers that event, but the child's $on body isn't called.

What am I missing?

Upvotes: 2

Views: 71

Answers (2)

georgeawg
georgeawg

Reputation: 48968

Most likely the event being broadcast happens before the listener is attached to the child component scope. It is best to avoid broadcasting events. Have events in parent elements modify Model values in the parent element. Use one-way < binding, to bind parent Model values to child component scope. Model values persist and are available regardless of when a child component is instantiated. Events are transient and can be missed.

Upvotes: 0

Abdullah Al Noman
Abdullah Al Noman

Reputation: 2878

Broadcast and emit works in different ways . Broadcast sends events towards child scopes while emit towards parent . Most probably you missed that . If you broadcast from rootScope this should probably work .

See details here also here

Upvotes: 1

Related Questions