我正在尝试分配格式化的值,下面的代码正在按顺序
export class AppComponent {
public urlObj = this._urlService.get('GET_CLIENT_ID');
url = this._urlService.formatURL('root', this.urlObj.URL);
constructor(private _urlService: UrlService) {
}
}
但是当我尝试直接更改urlObj.URL时,它不像
那样工作export class AppComponent {
public urlObj = this._urlService.get('GET_CLIENT_ID');
this.urlObj.URL = this._urlService.formatURL('root', this.urlObj.URL);
constructor(private _urlService: UrlService) {
}
}
这是Unexpected token at this.urlObj
答案 0 :(得分:2)
您的_urlService
在构造函数级别初始化。尝试在其中进行赋值操作:
export class AppComponent {
public urlObj;
constructor(private _urlService: UrlService) {
this._urlService.get('GET_CLIENT_ID');
this.urlObj.URL = this._urlService.formatURL('root', this.urlObj.URL);
}