I'm currently following a tutorial and the tutorial is making use of EventEmitter
. The code goes like this
@Output() ratingClicked: EventEmitter<string> = new EventEmitter<string>();
But it visual studio code gives me these errors:
Even in the angular website it looks like that code is correct.
I'm currently using Angular CLI: 1.7.4; Node: 8.11.1; Typescript: 2.8.1
EventEmitterlink. Use in components with the @Output directive to emit custom events synchronously or asynchronously, and register handlers for those events by subscribing to an instance.
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.
Conclusion. Use Eventemitter when transferring data from child component to parent component. Use Subject to transfer data from one component to another component.
The problem here is that an EventEmitter function can't return a value since it's asynchronous (although from rc2 it seems that this is optional by passing true to the new EventEmitter function? Even doing so won't fix this issue however). So isValid will always be true regardless of what the function returns.
You are probably using the node
native EventEmitter from node/index.d.ts
i.e.
import { EventEmitter } from 'events';
Change the import to the one from angular:
import { EventEmitter } from '@angular/core';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With