[英]How to bind an Image from App Component to HTML file in Angular 2
How to bind an Image from App Component to HTML file in Angular 2 This is my Relative path : assets/images/MyProfile_Summary_1x.png 如何将图像从App Component绑定到Angular 2中的HTML文件这是我的相对路径:asset / images / MyProfile_Summary_1x.png
export class MyProfile { image :"./assets/images/MyProfile_Summary_1x.png"; }
body { margin: 0; } #over img { margin-left: auto; margin-right: auto; display: block; }
<div id="over" style="position:absolute; width:100%; height:100%"> <img [src]="image"> </div>
actually, you are using colon
operator which is used for defining the type of any variable in ts
实际上,您正在使用
colon
运算符,该运算符用于定义ts
中任何变量的类型
so you just need to replace this 所以你只需要替换这个
image :"./assets/images/MyProfile_Summary_1x.png";
with 同
image = "./assets/images/MyProfile_Summary_1x.png";
if you still face the same issue then please verify your file path as well.
如果仍然遇到相同的问题,请同时验证文件路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.