I know I've to use ngClass or ngStyle but I'm not able to figure out how to pass that value. Here is my code.
strip.component.ts
import { ... } from '@angular/core';
@Component({
selector: 'app-strip',
templateUrl: './strip.component.html'
})
export class StripComponent implements OnInit {
...
@Input() widthValue: any; // getting this from parent component
staticKpi:{...}=[][]
}
strip.component.html
<ng-container>
<div *ngFor="let row of staticKpi">
<div class="rows" *ngFor="let item of row">
<div class="col-12">
<h2>{{widthValue}}</h2> <!-- this is printing correct value-->
...
</div>
</div>
</div>
</ng-container>
I've to decide width of rows class dynamically in scss something like this:
strip.component.css
.rows {
display: inline-block;
width: calc(100%/widthValue); // <----- here
text-align: left !important;
background: red;
}
I could have used col-{{widthValue}} in HTML but no, I've been told that it has to be from the width property from css.
Please help me. I'm not sure how to use ngClass here.
ngStyleto set the width dynamically.[style.width]="(100/widthValue)+'%'"or[ngClass]="'col-'+widthValue"[style.width]="widthValue?(100/widthValue)+'%':'1%'"