for working with ag-Grid, my suggestion is to set the class for the row and have that class be the one that is applying any styles you need for each case. I am suggesting going with class rather than direct styles because it is cleaner and faster (see here Inline Styles vs Classes)
the way to do this I think is shown here in ag-Grid documentation https://www.ag-grid.com/javascript-grid-row-styles/#row-class-rules
and specifically I think that this example is the cleanest and most direct.
gridOptions.rowClassRules: {
// apply green to 2008
'rag-green-outer': function(params) { return params.data.year === 2008},
// apply amber 2004
'rag-amber-outer': function(params) { return params.data.year === 2004},
// apply red to 2000
'rag-red-outer': function(params) { return params.data.year === 2000}
}
OR the shorthand version
gridOptions.rowClassRules: {
'rag-green': 'data.age < 20',
'rag-amber': 'data.age >= 20 && data.age < 25',
'rag-red': 'data.age >= 25'
}
Original Answer
direct answer is to bind to [ngStyle] like the example here that I lifted directly from angular.io here https://angular.io/guide/template-syntax#ngStyle
<div [ngStyle]="currentStyles">
This div is initially italic, normal weight, and extra large (24px).
</div>
this.currentStyles = {
'font-style': this.canSave ? 'italic' : 'normal',
'font-weight': !this.isUnchanged ? 'bold' : 'normal',
'font-size': this.isSpecial ? '24px' : '12px'
};
but I would also suggest that you try out style binding, which is using the template syntax to set styles dynamically based on content.
<div [style.background-color]="isFordCar(data) ? 'blue' : 'green'" >
</div>
OR better yet, why not use a class, which is ultimately cleaner and shares the same kind of binding syntax
<div [class.ford]="isFordCar(data)" >
</div>
ag-grid
makes that easy or hard though. – Heretic Monkey