par*_*ara 3 javascript typescript angular5
我在Angular5中使用typescript创建了getter-setter,如下所示: -
private _locations: Array<string> = [];
constructor() { }
/**
* Getter locations
* @return {Array<string>}
*/
public get locations(): Array<string> {
return this._locations;
}
/**
* Setter locations
* @param {Array<string>} value
*/
public set locations(value: Array<string>) {
this._locations = value;
}
Run Code Online (Sandbox Code Playgroud)
当我尝试访问方法位置时
this.signUpService.locations();
Run Code Online (Sandbox Code Playgroud)
我收到一个错误: [ts] Cannot invoke an expression whose type lacks a call signature. Type 'string[]' has no compatible call signatures.
this.signUpService.locations();
没有调用getter.他们只是得到了
const value = this.signUpService.locations;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
368 次 |
| 最近记录: |