“Eventemitter в угловой” Ответ

Угловое излучение событий

  @Output() open: EventEmitter<any> = new EventEmitter();


  toggel() {
  	this.open.emit(null);
  }	
Gorgeous Gentoo

Eventemitter в угловой

So, how to use it properly?
Simply use it to emit events from your component. Take a look a the following example.

@Component({
    selector : 'child',
    template : `
        <button (click)="sendNotification()">Notify my parent!</button>
    `
})
class Child {
    @Output() notifyParent: EventEmitter<any> = new EventEmitter();
    sendNotification() {
        this.notifyParent.emit('Some value to send to the parent');
    }
}

@Component({
    selector : 'parent',
    template : `
        <child (notifyParent)="getNotification($event)"></child>
    `
})
class Parent {
    getNotification(evt) {
        // Do something with the notification (evt) sent by the child!
    }
}
How not to use it?
class MyService {
    @Output() myServiceEvent : EventEmitter<any> = new EventEmitter();
}
Stop right there... you're already wrong...
Aamir Farooq

Что делает излучение событий в угловом

Data flows into your component via property bindings and flows out of your component through event bindings. If you want your component to notify his parent about something you can use the Output decorator with EventEmitter to create a custom event.
Cruel Cassowary

Ответы похожие на “Eventemitter в угловой”

Вопросы похожие на “Eventemitter в угловой”

Больше похожих ответов на “Eventemitter в угловой” по JavaScript

Смотреть популярные ответы по языку

Смотреть другие языки программирования