Reputation: 518
Let's assume that you have div
in some component's html template:
<div [ngStyle]="{'grid-template-columns': repeat(5, 20%)}"></div>
How to make repeat()
css function work in that scenario?
Upvotes: 1
Views: 445
Reputation: 347
Consider using [style.<property>]="'<value>'"
in order to have better control over which styles are applied.
<div
class="meal-list"
[style.grid-template-rows]="'auto repeat(' + store.mealsToShow() + ', 1fr)'"
[style.grid-template-columns]="'repeat(' + store.mealsToShow() + ', 1fr)'"
>
Angular reference: https://angular.dev/guide/templates/binding#css-style-properties
Upvotes: 0
Reputation: 564
I just came across this question and thought I'd share how I used it in my code.
<div [ngStyle]="{'grid-template-columns': 'repeat(' + buttonData.length + ', 1fr)'}"></div>
Upvotes: 0
Reputation: 617
You just need to put the right side in quotations:
<div [ngStyle]="{'grid-template-columns': 'repeat(5, 20%)'}"></div>
Upvotes: 1