我正在尝试使用自定义管道*ngFor使用带有ngModel的输入字段来过滤我的循环.使用我的其他自定义管道(sortBy),它工作得很好.但是,过滤管似乎使得没有数据出现.我还在学习这个,我尝试了一些变化无济于事:
-filter: term
-filter: {{term}}
-filter: 'term'
-filter" {{'term'}}
Run Code Online (Sandbox Code Playgroud)
所以我认为问题可能在于代码中的其他地方.如果有人可以提供帮助,我会非常感激.
这是我的代码:
HTML组件
<div style="text-align:center">
<h1>
Welcome to {{title}}!!
</h1>
</div>
<h2>Please choose your favorite song: </h2>
<form id="filter">
<label>Filter people by name:</label>
<input type="text" name="term" [(ngModel)]="term" />
</form>
<table class="table">
<thead>
<tr>
<th>Title</th>
<th>Artist</th>
<th>Likes</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let song of songs | filter:term| sortBy: 'likes'; let i = index">
<td>{{song.title}}</td>
<td>{{song.artist}}</td>
<td>{{song.likes}}
<i class="fa fa-heart-o" aria-hidden="true" *ngIf="song.likes < 1"></i>
<i class="fa fa-heart" aria-hidden="true" *ngIf="song.likes >= 1"></i> …Run Code Online (Sandbox Code Playgroud)