在触发或调用更改函数时,分页数据不会更新,它仍保留在init调用时呈现的先前数据。
TS代码:
ngOnInit() {
this.http.get('https://jsonplaceholder.typicode.com/posts/').subscribe(
data => {
this.DataArray = data.json();
console.log(data.json());
}
);
}
public change(event): void {
let newVal = event.target.value;
this.http.get('https://jsonplaceholder.typicode.com/posts/').subscribe(
data => {
this.DataArray = []
this.DataArray.push(data.json()[newVal]);
}
);
}
HTML代码
<tr *ngFor="let data of DataArray">
<td><a href="javascript:"><i class="fa fa fa-eye" data-
toggle="modal" data-target="#myModal"></i></a> <a
href="javascript:"><i class="fa fa-pencil"></i></a> <a
href="javascript:"><i class="fa fa-line-chart"></i>
</a> <a href="javascript:"><i class="fa fa-trash-o">
</i></a></td>
<td>{{data.id}}</td>
<td>{{data.title}}</td>
<td>{{data.type}}</td>
<td>{{data.smsFlag ? "Yes":"No"}}</td>
</tr>