While going through an Angular 4 tutorial I found a new way of getting/setting parameter in function.
onValueChange(data?: any)
What does the ? do?
? sign denotes optional. Meaning that if you don't pass the value to function, it won't throw an error.
For example:
This is your function
onValueChange(data?: any) {
console.log(data);
}
onValueChange('somedata'); // will print 'somedata' in the console
onValueChange(); // will print undefined but it won't throw an error
Summary: You can call this function without passing the value as it is optional.
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