Reputation: 153
I have to pass a boolean value to the Parent Component but while doing so I am getting an error stating that " Type 'false' is not assignable to type 'EventEmitter'. "
Here is the code for it,
@Output() isTimeBoundAccessEnabled = new EventEmitter();
and here is how I am assigning a boolean Value as FALSE when a certain condition fails
this.isTimeBoundAccessEnabled = false ;
What is exactly the mistake in my code?
Upvotes: 0
Views: 4189
Reputation: 236
Looks like you are not Emitting the value and assigning it. Make sure to emit the values while using the emitter. In your case you can use what other in the above answers have mentioned. Also make sure to use correct type of EventEmitter.
this.isTimeBoundAccessEnabled.emit(false);
Upvotes: 0
Reputation: 3415
To pass false
to the parent (from the child component) you should emit
values like:
// in child component
this.someEventEmitter.emit(false);
Then the parent has an event handler for that like
<MyChild (customEvent)="handleEvent($event)"> ...
and in parent class we have handleEvent
handleEvent($event){
console.log($event); // should be `false` if child executed the above code
}
Upvotes: 2
Reputation: 2332
The right way is:
@Output() isTimeBoundAccessEnabled = new EventEmitter<boolean>();
this.isTimeBoundAccessEnabled.emit(false);
Upvotes: 2