angular - 有什么作用?在 Angular 函数参数中是什么意思?
问题描述
在浏览 Angular 4 教程时,我发现了一种在函数中获取/设置参数的新方法。
onValueChange(data?: any)
做什么的?
?
解决方案
?
符号表示optional
。这意味着如果您不将值传递给函数,它将不会抛出error
.
例如:
这是你的功能
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
摘要:您可以在不传递值的情况下调用此函数,因为它是可选的。
推荐阅读
- javascript - 如何启用自动完成和
- java - 无法在 AWS Lambda 中获取 Java 资源文件
- amazon-web-services - 无法在 aws cloud9 中使用 Python 中的 selenium 运行 chromedriver
- java - 获取某个topic的kstream后如何从ktable中读取完整的历史记录
- ruby-on-rails - 所有者财产的默认顺序
- drupal-7 - 如何提供部分文本的链接
- time-series - 未启用 DFS 或系统不是数据节点。?
- python - 如何从 ViewSet 类创建 Django REST Framework View 实例?
- php - 如何在文件编号后添加自动递增编号(文件编号是表格的属性)
- python - python中的方法解析顺序