我正在尝试在angular2中插入图像.
我的图片名称保存在mypicture变量中.
我试过这种方式< img [src] =“../../../ public / img / {{mypicture}}”/>但它不起作用.
我的图片名称保存在mypicture变量中.
我试过这种方式< img [src] =“../../../ public / img / {{mypicture}}”/>但它不起作用.
我在控制台中看到此错误:
Error: Uncaught (in promise): Template parse errors: Parser Error: Got interpolation ({{}}) where expression was expected
解决方法
而不是那样做
在绑定之前联系完整路径
在绑定之前联系完整路径
例如:
public fullPath:string; public myPicture:string; getMyPicture(){ this.fullPath = "../../../public/img/"+ this.myPicture; }
HTML
<img [src]="fullPath" />