In my child component, on click of a button a process fires and returns a boolean. I need to capture this boolean in my parent component and enable/disable a button. I have never used @Output() before. I have created a sample to show the issue. In the dev tools I get this error:
ERROR TypeError: _co.onclickValidateAndSave is not a function
child.component.ts
import { Component, OnInit, EventEmitter, Output } from '@angular/core';
@Component({
selector: 'app-child',
templateUrl: './child.component.html',
styleUrls: ['./child.component.scss']
})
export class ChildComponent implements OnInit {
//passing value to parent component thru event payload
bSuccess: boolean = false;
@Output()
public clickValidateAndSave: EventEmitter<boolean> = new EventEmitter<boolean>();
constructor() { }
ngOnInit() {
}
public onclickValidateAndSave() {
this.clickValidateAndSave.emit(this.bSuccess);
//not being logged
console.log(this.bSuccess);
}
toggleSuccess() {
this.bSuccess = !this.bSuccess;
}
}
Here is child.component.html:
<div>
<div class="form-group">
<button class="btn btn-default"
(click)="toggleSuccess()">
Toggle Success
</button>
</div>
</div>
parent.component.ts:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-parent',
templateUrl: './parent.component.html',
styleUrls: ['./parent.component.scss']
})
export class ParentComponent implements OnInit {
disableBtn: boolean = false;
constructor() { }
ngOnInit() {
}
handleClickOnChild(bSuccess) {
this.disableBtn = !bSuccess
}
}
and parent.component.html
<app-child (clickValidateAndSave)="handleClickOnChild($event)"></app-child>
<div class="row col-mg-6">
<button type="submit" class="btn btn-primary" [disabled]="disableBtn" ngDefaultControl name="name">
Submit for Approval
</button>
</div>