Javascript 如何为Priming的p-card动态分配背景?
我必须根据状态将背景分配给p卡(预涂)。示例:如果状态为失败,则为红色,黄色表示警告,绿色表示成功。我认为的一种方法是使用样式属性。p-card的style属性需要一个对象。因此,如果我们操纵该对象,我们可以改变bg颜色Javascript 如何为Priming的p-card动态分配背景?,javascript,angular,sass,primeng,styling,Javascript,Angular,Sass,Primeng,Styling,我必须根据状态将背景分配给p卡(预涂)。示例:如果状态为失败,则为红色,黄色表示警告,绿色表示成功。我认为的一种方法是使用样式属性。p-card的style属性需要一个对象。因此,如果我们操纵该对象,我们可以改变bg颜色 <p-card header="Simple Card" [style]="styleOBJ"> some text </p-card> // in .ts file styleOBJ = {'backg
<p-card header="Simple Card" [style]="styleOBJ">
some text
</p-card>
// in .ts file
styleOBJ = {'background':'lightblue'}
if(status == 'success') {
styleOBJ = {'background':'green'}
} else ...
一些文本
//在.ts文件中
styleOBJ={'background':'lightblue'}
如果(状态=‘成功’){
styleOBJ={'background':'green'}
}否则。。。
首先禁用组件中的视图封装,然后添加样式
@Component({
selector: 'my-component',
templateUrl: './app/components/my.html',
styleUrls: ['./app/components/my.css'],
encapsulation: ViewEncapsulation.None
})
然后在你的p-card上添加一些ngClass的getter