2017-07-19 117 views
0

我試圖使用ng2-smart-table插件顯示產品數據。平均堆棧:將產品顯示到ng智能表

我能夠在瀏覽器日誌中獲取產品,但我需要顯示相同的onChange下拉值。

\程序\分量\佈局\白紙\空白page.component.html

<form role="form"> 
     <fieldset class="form-group"> 
      <label>Select Category</label><br/><br/> 
       <select [(ngModel)]="selectedObject" (ngModelChange)="onChange(selectedObject)" name="selectedObject" class="form-control"> 
         <option>--Select Category--</option> 
         <option *ngFor="let category of categories" [value]="category._id">{{category.category_name}}</option> 
       </select> 
     </fieldset> 
    </form> 


//This is where table data is displaying, need to show my data here 

<ng2-smart-table [settings]="view_update_items_settings" [source]="view_update_items_smart_data" (userRowSelect)="onUserRowSelect($event)" class="table table-hover table-striped"></ng2-smart-table> 

應用程序\分量\佈局\白紙\空白page.component.ts

onChange(categoryid) { 

this.productService.getProductsOncategory(categoryid).subscribe(data => { 
    if (data.success) { 
    //this.selectedObject = data.mainProducts; 
    console.log(data) 
    console.log('Products obtained'); 
    } else { 
    console.log('Not obtained!'); 
    } 
}); 

} 

應用程序\ SERVICES \ product.service.ts

getProductsOncategory(category_id){ 
    console.log(category_id) 
    let catUrl="http://10.*.*.*:5000/products/getProductsOncategory" 
    let headers = new Headers(); 
    headers.append('Content-Type','application/json'); 
    let catIdObj = JSON.stringify({category_id:category_id}) 
    console.log(catIdObj) 
    return this.http.post(catUrl,catIdObj,{headers:headers}) 
    .map((response:Response)=>response.json()) 
    .do(data=>console.log(JSON.stringify(data))) 
    .catch(this.handleError); 
} 

在選擇自降值的下降,我得到了我的瀏覽器發佈的數據,我需要在我的NG2智能表的數據顯示相同的

enter image description here

回答

0

綁定「view_update_items_smart_data」你從服務器獲取。

onChange(categoryid) { 

this.productService.getProductsOncategory(categoryid).subscribe(data => { 
    if (data.success) { 
    //this.selectedObject = data.mainProducts; 
    console.log(data) 
    console.log('Products obtained'); 
    this.view_update_items_smart_data.load(data); 
    } else { 
    console.log('Not obtained!'); 
    } 
}); 

} 

欲瞭解更多信息,可以參考 https://akveo.github.io/ng2-smart-table/#/examples/populate-from-server