在学习 Angular 4 教程时,我发现了一种在函数中获取/设置参数的新方法。
onValueChange(data?: any)
?
有什么作用?
最佳答案
?
符号表示可选
。这意味着如果您不将值传递给函数,它就不会抛出一个错误
。
For example:
这是你的功能
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
总结:您可以在不传递值的情况下调用此函数,因为它是可选的。
关于angular - 什么?在 Angular 函数参数中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59465060/