事件更改时数据表不会刷新。 - Angular 4

时间:2017-10-11 06:19:43

标签: angular angular4-httpclient

在触发或调用更改函数时,分页数据不会更新,它仍保留在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>&nbsp;&nbsp;<a 
     href="javascript:"><i class="fa fa-pencil"></i></a>&nbsp;&nbsp;<a 
     href="javascript:"><i class="fa fa-line-chart"></i>
     </a>&nbsp;&nbsp;<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>

0 个答案:

没有答案