[英]Can I make a parameter optional in a Typescript definition and function call?
Here is my call: 这是我的电话:
this.enumService.getData('ContentStatus'),
It's giving an error as my definition is: 由于我的定义是错误的:
getData(controller: any, params: any);
The function looks like this: 该函数如下所示:
getData = (controller, params) => {
if (!params) { params = "" }
var defer = this.$q.defer();
How can I fix the definition and the function so a null is allowed? 如何修复定义和函数,以便允许使用null?
For your case the declaration ?
对于您的情况,声明
?
: :
getData(controller: any, params?: any);
And if you are defining in TypeScript you can use default parameters =
: 如果您在TypeScript中定义,则可以使用默认参数
=
:
getData = (controller, params = "") => {
var defer = this.$q.defer();
The documentation can be found on the typescript following construction function create(name: string, animalOptions?: AnimalOptions): Animal;
该文档可以在构造
function create(name: string, animalOptions?: AnimalOptions): Animal;
的打字稿上找到function create(name: string, animalOptions?: AnimalOptions): Animal;
use "?" 采用 ”?”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.