Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何为Priming的p-card动态分配背景?_Javascript_Angular_Sass_Primeng_Styling - Fatal编程技术网

Javascript 如何为Priming的p-card动态分配背景?

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卡(预涂)。示例:如果状态为失败,则为红色,黄色表示警告,绿色表示成功。

我认为的一种方法是使用样式属性。p-card的style属性需要一个对象。因此,如果我们操纵该对象,我们可以改变bg颜色

<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