这个问题在这里已有答案:
我需要将* ngFor循环绑定到div,但我还需要在满足* ngIf条件后才显示它 .
但是Angular 4不会让你把它们结合起来 .
我的代码:
<ion-item class="item-icon-left item-icon-right positive"
*ngFor="let phone of contact.shared.phones"
*ngIf="phone.phone_number !== ''">
<i class="icon ion-ios-telephone"></i>
<small>{{phone.phone_type}} phone</small>
<br>{{phone.phone_number | tel}}
<i class="icon ion-android-close" (click)="removePhone($index, phone)"></i>
</ion-item>
我收到以下错误:
一个元素上不能有多个模板绑定 . 仅使用一个名为“template”的属性或以*为前缀
那你怎么做呢?
1 回答
将* ngFor指令元素包装在ng-container中: