如何根据记录长度动态添加bootstrao col-lg {n}

时间:2018-06-11 10:48:28

标签: angular bootstrap-4

以下是我想要的结果

1.let suppose i have only one record then it should take "col-lg-12"
2.if i have 2 records then it should be like "col-lg-6" & "col-lg-6"
3.if i have 3 records then it should be like "col-lg-4" & "col-lg-4" & "col-lg-4".
4.if i have four record then it should be like first row of col-lg-4 each and next row will be col-lg-12


How can i do this

1 个答案:

答案 0 :(得分:0)

我已添加此代码,请检查

export class AppComponent implements OnInit {

    records=['data','data2'];
    constructor(){}

    ngOnInit(){}    
}

你的Html文件应该是这样的

<div *ngFor="let record of records;let i=index" class="col-md-{{12/+records.length}}" >
{{record}}{{i/1}}
</div>