Child listens for parent event in Angular 2

For the sake of posterity, just thought I’d mention the more conventional solution to this: Simply obtain a reference to the ViewChild then call one of its methods directly. @Component({ selector: ‘app-child’ }) export class ChildComponent { notifyMe() { console.log(‘Event Fired’); } } @Component({ selector: ‘app-parent’, template: `<app-child #child></app-child>` }) export class ParentComponent { @ViewChild(‘child’) … Read more

Node.js – inheriting from EventEmitter

As the comment above that code says, it will make Master inherit from EventEmitter.prototype, so you can use instances of that ‘class’ to emit and listen to events. For example you could now do: masterInstance = new Master(); masterInstance.on(‘an_event’, function () { console.log(‘an event has happened’); }); // trigger the event masterInstance.emit(‘an_event’); Update: as many … Read more

Delegation: EventEmitter or Observable in Angular

Update 2016-06-27: instead of using Observables, use either a BehaviorSubject, as recommended by @Abdulrahman in a comment, or a ReplaySubject, as recommended by @Jason Goemaat in a comment A Subject is both an Observable (so we can subscribe() to it) and an Observer (so we can call next() on it to emit a new value). … Read more

techhipbettruvabetnorabahisbahis forumuedueduedusedusedusedusedueduedusedus