angular 4 中 *ngFor 和*ngIf 一起使用

原创 Been101 随笔 ng4 208阅读 2018-01-20 19:22:50 举报

在同一个标签中 同时使用 ngFor 和 ngIf 会报错 Can't have multiple template bindings on one element. Use only one attribute named 'template' or prefixed with
是因为 The
in *ngFor makes Angular to add a <template> tag. On a <template> tag this doesn't make sense and therefore here structural directives have a different syntax.

vue中使用就很简单
<li v-for = "item in lists" v-if="item.type == 1">{{item.type}}</li>
angular 4 中就要这么用了

<ng-container ngFor = "let item of lists">
<li
ngIf = "item.type == 1">{{itemtype}}</li>
</ng-container>

评论 ( 0 )
最新评论
暂无评论

赶紧努力消灭 0 回复