Reputation: 93
I have to assign background to p-card (of primeng) depending upon the status. Example: red if status is failed, yellow for warning and green for success.
Upvotes: 1
Views: 7122
Reputation: 1333
First of all disable Disable view encapsulation in your component, and then add the styles,
@Component({
selector: 'my-component',
templateUrl: './app/components/my.html',
styleUrls: ['./app/components/my.css'],
encapsulation: ViewEncapsulation.None
})
And than add some getter for ngClass to yours p-card
Upvotes: 0
Reputation: 93
one way i have figured is using style property. The style property of p-card expects an object. So if we manipulate that object, we can change the bg color.
<p-card header="Simple Card" [style]="styleOBJ">
some text
</p-card>
// in .ts file
styleOBJ = {'background':'lightblue'}
if(status == 'success') {
styleOBJ = {'background':'green'}
} else ...
Upvotes: 5