Angular 6 - 访问变量外部函数不起作用

Ros*_*erg 1 angular

export class EditClientComponent implements OnInit {

 apiEndPoint: 'http://localhost:1337/upload';

 fileChange(event) {
 //...
    this.http.post(`${this.apiEndPoint}`, formData, httpOptions)
 //...
 }
}
Run Code Online (Sandbox Code Playgroud)

我得到一个奇怪的错误:

status: 404, statusText: "Not Found", url: "http://localhost:4100/undefined"...

这意味着,它不读apiEndPoint 所有,如果我取代${this.apiEndPoint}与实际的URL,它的工作原理.

我能做什么?

Rae*_*laf 5

将apiEndPoint的声明更改为=而不是:

apiEndPoint = 'http://localhost:1337/upload';
Run Code Online (Sandbox Code Playgroud)

您指定的变量类型不是初始值.