简体   繁体   English

Angular 4 使用从 something.component.ts 到 something.component.css 的值

[英]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.

相关问题 这个 noflo 组件有问题吗? - Is there something wrong with this noflo component? 从app.component.ts角路由 - Angular routing from app.component.ts 为什么要用角度的方法从“ some.component.ts”中使用“ import {SomeComponent}”,而不是从“ some.component.ts”中使用“ import SomeComponent”? - Why angular use `import { SomeComponent } from 'some.component.ts'` instead of `import SomeComponent from 'some.component.ts'` 在 render() 之前使用什么组件生命周期来做某事? - What component lifecycle to use to do something before render()? MaterializeCSS组件缺少关键的东西 - MaterializeCSS Component Missing Something Critical React - 从子组件更新 State,然后基于 State 做一些事情 - React - Updating State From a Child Component, Then Doing Something Based on State 如何从JSP获取值并将其注入Angular 5组件(main.ts) - How to get values from a JSP and inject them into the Angular 5 component (main.ts) 如何在角组件TS中调用组件 - How to call a component inside component TS in angular Angular app.component.ts 中jQuery代码的使用 - Use of jQuery code in Angular app.component.ts 如何在 Angular (component.ts) 中使用 JS function - How to use JS function in Angular (component.ts) Collapsible Sidebar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM