oni3619
oni3619

Reputation: 153

Type 'false' is not assignable to type 'EventEmitter<any>'

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

Answers (3)

Onkar Nirhali
Onkar Nirhali

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

Louay Al-osh
Louay Al-osh

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

Benny Halperin
Benny Halperin

Reputation: 2332

The right way is:

@Output() isTimeBoundAccessEnabled = new EventEmitter<boolean>();

this.isTimeBoundAccessEnabled.emit(false);

Upvotes: 2

Related Questions