I am using StreamControllers with Events, and essentially I have a 3 level component heirarchy lets call them, A,B,C. The heirarchy is A -> B -> C.
The origin of the eve
I think it is easier just to create an "event bus" singleton service that is injected in Component A and Component C.
Here is the code:
class Event {
// your data
}
@Injectable()
class EventBus {
final StreamController _onEventStream = new StreamController();
Stream onEventStream = null;
static final EventBus _singleton = new EventBus._internal();
factory EventBus() {
return _singleton;
}
EventBus._internal() {
onEventStream = _onEventStream.stream;
}
onEvent(Event event) {
_onEventStream.add(selection);
}
}
@Component(
selector: 'C',
templateUrl: 'C.html',
providers: const [
EventBus
]
)
class C {
final EventBus _eventBus;
C(this._eventBus);
onAction() {
_eventBus.onEvent(new Event());
}
}
@Component(
selector: 'A',
templateUrl: 'A.html',
providers: const [
EventBus
]
)
class A {
final EventBus _eventBus;
A(this._eventBus) {
_eventBus.onEventStream.listen((Event e) => /* do something with the event */)
}
}