我在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;
}
当我尝试访问方法位置时
this.signUpService.locations();
我收到错误:[ts] Cannot invoke an expression whose type lacks a call signature. Type 'string[]' has no compatible call signatures.
答案 0 :(得分:8)
this.signUpService.locations();
getters 未被调用。他们只是得到
const value = this.signUpService.locations;