[英]Angular 4 use the values from something.component.ts to the something.component.css
I am a bit new on Angular 4 so this might be a bit stupid question.. I got a value photourl:string;
我对 Angular 4 有点
photourl:string;
所以这可能是一个有点愚蠢的问题.. 我得到了一个值photourl:string;
on my component.ts which contains the url of an image from my firebase database.. and I want to use this url as background-image for a div I got in my component.html so dispite {{photourl}} works fine in my component.html {{photourl}} in not recognised in my component.css.. Is there any way I can use typescript values in my component.css file directly or I need to use javascript from component.ts to intervene in the component.css?在我的 component.ts 上,它包含来自我的 firebase 数据库的图像的 url .. 我想使用这个 url 作为我在 component.html 中获得的 div 的背景图像,所以尽管 {{photourl}} 在我的component.html {{photourl}} 在我的 component.css 中无法识别。有什么办法可以直接在我的 component.css 文件中使用 typescript 值,或者我需要使用 component.ts 中的 javascript 来干预组件。 css?
Use the ngStyle
directive.使用
ngStyle
指令。
<my-component [ngStyle]="{ 'background-image': photoUrl }"></my-component>
Source: https://angular.io/api/common/NgStyle来源: https : //angular.io/api/common/NgStyle
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.