Angualr2 * ngFor不绑定数据

时间:2018-06-12 13:11:19

标签: angular angular2-forms

请帮助我,为什么我无法绑定我的数据

someval(value){
   let data=JSON.stringify(value);
  let _pagedItems= this.auction.find(e=>e.uniqueid=data);
  console.log(_pagedItems);   
}

将pring数据控制为{id:1,uniqId:" Abc"} 这里我将过滤来自this.auction数据im绑定的数据

<table class="table table-bordered">
    <thead>
      <tr>
        <th>Firstname</th>
      </tr>
    </thead>
    <tbody>
      <tr *ngFor="let value of _pagedItems">
        <td>{{value.uniqueid}}</td>
      </tr>
    </tbody>
  </table>

2 个答案:

答案 0 :(得分:1)

find将仅返回可能是对象的匹配项,您需要使用过滤器

 let _pagedItems= this.auction.filter(e=>e.uniqueid=data);

如果您确定总是得到一个对象,则不应使用ngFor,只需使用

<tr >
        <td>{{_pagedItems.uniqueid}}</td>
</tr> 

答案 1 :(得分:0)

您尚未将_pagedItems变量用作类变量。 并且您需要使用返回Array的用户过滤器。

尝试使用此代码。

希望这个答案对你有所帮助。

export class AppComponent implements OnInit {
    public _pagedItems = [];
    someval(value){
        let data=JSON.stringify(value);
        this._pagedItems= this.auction.filter((e)=> {return e.uniqueid=data });
        console.log(this._pagedItems);   
    }
}
相关问题