是否可以将单击事件绑定到插值?因为当我尝试执行下面的代码时,我得到了以下代码
错误:未捕获(在promise中):
错误:模板解析错误:
解析器错误:获取插值({{}}),其中上传({{config.fileLocation}})的第7列应为表达式
这是我们有错误插值的模板,
<mat-card-actions>
<button mat-raised-button type="button" (click)="upload({{config.fileLocation}})">Upload</button>
</mat-card-actions>这是期望执行的角度组件。
upload(location = "/tmp/") {
this.loader.open();
const fileBrowser = this.fileInput.nativeElement;
if (fileBrowser.files && fileBrowser.files[0]) {
const formData: FormData = new FormData();
formData.append('file', fileBrowser.files[0]);
formData.append('data', JSON.stringify({
"method": "filesystem.put",
"params": [location + fileBrowser.files[0].name, { "mode": "493" }]
}));
this.http.post(this.apiEndPoint, formData).subscribe(
(data) => {
this.loader.close();
this.snackBar.open("your files are uploaded", 'close', { duration: 5000 });
},
(error) => {
this.loader.close();
this.dialog.errorReport(error.status, error.statusText, error._body);
}
);
};
}发布于 2018-02-17 05:01:41
只是
(click)="upload(config.fileLocation)"切勿将{{}}与[foo]="..."或(bar)="..."一起使用
[]和()已经将该属性标记为角度绑定。{{}}还只允许字符串绑定(对每个值进行字符串化),而其他的则允许绑定对象值。
https://stackoverflow.com/questions/48834760
复制相似问题