<ul class="list-group" *ngFor="let head of channelDisplayHeads">
<li class="list-group-item" *ngFor="let channel of channelList" ngIf="channel.channel.indexOf('head') === 1">
<strong>{{ head }}</strong>
</li>
</ul>在这里,ngFor循环显示组头,如"A“、"B”、"C“等。对于每个组头,我试图列出以For循环所在的字母开头的通道。我正在尝试使用ngIf来完成此行为,但它似乎并不像预期的那样工作。请指点!
发布于 2017-12-06 06:16:36
这里有一些问题。
*ngIf。*ngFor和*ngIf。使用ng-container作为其中之一。这是角元素,它不会在html中呈现,只用于角指令。head变量作为字符串传递。如果要检查元素,请删除引号。发布于 2017-12-07 05:14:41
最后,此代码按预期工作。
<ul class="list-group" *ngFor="let head of channelDisplayHeads">
<h1>{{ head }}</h1>
<ng-container *ngFor="let channel of channelList">
<li class="list-group-item" *ngIf="channel.channel.substr(0, 1) === head">
<strong></strong>
<strong>{{ channel.channel }} </strong>
</li>
</ng-container>
</ul>发布于 2017-12-06 06:12:57
您忘了*了,请按下面给出的内容,试一试,
*ngIf="channel.channel.indexOf('head') === 1"下面是我的工作
模板
<ul *ngFor="let hero of numbers" >
<div *ngIf="hero==1">
{{hero}}
</div>
</ul>ts文件
numbers: Array<string> = new Array<string>();
constructor()
{
this.numbers.push('1');
this.numbers.push('2');
this.numbers.push('3');
}https://stackoverflow.com/questions/47667864
复制相似问题