You can use getters and setters with a single @input with getters and setters to achieve the same result as with @output and EventEmitters as below:
private _childItem: any;
@Input()
get childItem() {
return this._childItem;
}
set childItem(val) {
this._childItem = val;
}
ngOnInit() {
this.childItem = 'hello'; // whether I set the private field or the public setter I get the same result
}
Would it be possible to explain why this is a worse approach than EventEmitters please?
Description
You can use getters and setters with a single @input with getters and setters to achieve the same result as with @output and EventEmitters as below:
Would it be possible to explain why this is a worse approach than EventEmitters please?
What is the affected URL?
https://angular.io/guide/two-way-binding
Please provide the steps to reproduce the issue
No response
Please provide the expected behavior vs the actual behavior you encountered
No response
Please provide a screenshot if possible
No response
Please provide the exception or error you saw
No response
Is this a browser-specific issue? If so, please specify the device, browser, and version.
No response
The text was updated successfully, but these errors were encountered: