我有跟随对象
public countries= [
{code: 'AE' , country_name: 'United Arab Emirates', color: '#eea638'},
{code: 'AF' , country_name: 'Afghanistan', color: '#eea638'},
{code: 'AL' , country_name: 'Albania', color: '#eea638'},
{code: 'AM' , country_name: 'Armenia', color: '#eea638'},
{code: 'US' , country_name: 'United State',color: '#eea638'},
{code: 'AR' , country_name: 'Argentina', color: '#eea638'},
{code: 'AT', country_name: 'Austria', color: '#eea638'},
{code: 'AU', country_name: 'Australia', color: '#eea638'}
]
所以我想根据这个对象列表动态地设置 div 颜色。我试图这样做:
<div *ngFor="let country of countries">
<p class="m-b-10">{{country.country_name}}
<span class="f-right">{{country.code}}</span>
</p>
<div class="progress">
<div class="progress-bar" ng-style="{'background-color': country.color}" [style.width]="'75%'"></div>
</div>
但它不起作用。请你帮助我好吗?