繁体   English   中英

如何将图像从App Component绑定到Angular 2中的HTML文件

[英]How to bind an Image from App Component to HTML file in Angular 2

如何将图像从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> 

实际上,您正在使用colon运算符,该运算符用于定义ts中任何变量的类型

所以你只需要替换这个

image :"./assets/images/MyProfile_Summary_1x.png";

image = "./assets/images/MyProfile_Summary_1x.png";

如果仍然遇到相同的问题,请同时验证文件路径。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM