Reputation: 4160
I'm a newby to typescript / angular.
Porting an application from Angular13 to Angular16, including material and ngbootstrap. My old html and mat table for which the row color is determined in typescript. It looked like this:
<tr mat-row [ngClass]="determineRowClass(row)" *matRowDef="let row; columns: displayedColumns;"></tr>
The typescript would then return:
public determineRowClass(row: RegistrationObject) {
if (row.registrationHistory?.registered === 'nee') {
// Red background when object has been deregistered.
return 'alert-danger';
}
else if (row.registrationHistory?.underReview === 'ja') {
// Blue background when object is under review.
return 'alert-info';
}
return '';
}
Looking in the debugger, I can see the following:
<tr _ngcontent-ng-c2810724556="" role="row" mat-row="" class="mat-mdc-row mdc-data-table__row cdk-row alert-danger ng-star-inserted" ng-reflect-ng-class="alert-danger">
...
So it is picked up.
Unfortunately, looking at the generated css I see this:
The only way I can overcome this is by adding my own style classes.. Which seems to beat the idea of using predefined styles from libraries.
.alert-danger {
background-color: #F8D7DAFF !important;
}
This is not the only occurrence of this problem. I've got this all over my application where material components seem to have their own 'idea' on what style is better. It drives me a bit mad. Do I miss something?
Upvotes: 1
Views: 400
Reputation: 3236
There are actual multiple issues here. Your issue is not with Angular MAterial, but with Bootstrap, which has been refactored. It doesn't work the same way.
background-color: var(--bs-alert-bg)
if you wish. That's what the code you see makes you able to do. It defines a color variable depending on your theme.--bs-alert-bg
variable, but does not apply to your tr..alert
, which applies the color : https://getbootstrap.com/docs/5.3/components/alerts/Upvotes: 0