我正在尝试在angular2中插入图像.我的图片名称保存在mypicture变量中.我试过这种方式,<img [src]="../../../public/img/{{mypicture}}" />但它没有用.
我在控制台中看到此错误:
Error: Uncaught (in promise): Template parse errors:
Parser Error: Got interpolation ({{}}) where expression was expected
Run Code Online (Sandbox Code Playgroud)
而不是在绑定之前联系完整路径
例如:
public fullPath:string;
public myPicture:string;
getMyPicture(){
this.fullPath = "../../../public/img/"+ this.myPicture;
}
Run Code Online (Sandbox Code Playgroud)
HTML
<img [src]="fullPath" />
Run Code Online (Sandbox Code Playgroud)
小智 7
你只需要混合"和".
<img [src]="'../../../public/img/' + mypicture" />
Run Code Online (Sandbox Code Playgroud)
而已.快速简便的修复.
| 归档时间: |
|
| 查看次数: |
26138 次 |
| 最近记录: |