如何在 Angular 2 中将图像从 App 组件绑定(bind)到 HTML 文件 这是我的相对路径:assets/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>
最佳答案
实际上,您正在使用 colon
运算符,它用于定义 ts
中任何变量的类型
所以你只需要替换这个
image :"./assets/images/MyProfile_Summary_1x.png";
与
image = "./assets/images/MyProfile_Summary_1x.png";
if you still face the same issue then please verify your file path as well.
关于html - 如何将图像从 App 组件绑定(bind)到 Angular 2 中的 HTML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53832204/