I've a component with the following input
@Input() id: string
I would like this input to be mandatory, which means that if I call my component without specifying it, it would throw a js error.
I can do it in the ngOnInit
, but I imagine there is a keyword for this ?
You can throw error in ngOnInit method after checking input property:
ngOnInit() {
if (!id) {
throw new Error('No ID provided!');
}
}
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