ngstyle conditional code example
Example 1: ng style
<some-element [ngStyle]="{'max-width.px': widthExp}">...</some-element>
Example 2: ngstyle conditional
<div [ngClass]="{'class1': true, 'class2': false}"></div> <!--passed as an object-->
Example 3: conditional inline style angular
// ngStyle (conditional Style)
<div *ngFor='let [data] of [dataArray]; let i=index;'>
<h2 [style.background]="i>1? 'green': 'red'"> {{i}} {{data.title}} </h2>
</div>
//if the index of the element is 1 or 0, the background will be red, if it is over 1 the background will be green