我正在尝试使用 Angular2 ng Smart table 插件将数据从我的 API 加载到自定义组件。
我有我的组件,例如:
import { LocalDataSource } from 'ng2-smart-table';
import { ProductService } from '../../../services/product.service';
export class CategoryItemsComponent implements OnInit {
...
source: LocalDataSource;
constructor(private productService: ProductService,
private flashMessage: FlashMessagesService,
private router: Router,
http: Http) {
this.source = new LocalDataSource();
this.productService.getProductsOncategory(this.categoryid).subscribe((data) => {
this.source.load(data);
});
}
产品服务.ts
getProductsOncategory(category_id) {
let catUrl = "http://localhost:5000/products/getProductsOncategory"
let headers = new Headers();
headers.append('Content-Type', 'application/json');
let catIdObj = JSON.stringify({ category_id: category_id })
return this.http.post(catUrl, catIdObj, { headers: headers })
.map((response: Response) => response.json())
.do(data => console.log(JSON.stringify(data)))
.catch(this.handleError);
}
服务功能中使用的上述 API 在我的邮递员中完美运行。
现在我需要将该 API 中的 dame 数据加载到我的自定义组件中。
我收到此错误:
错误类型错误:this.data.slice 不是函数
在 LocalDataSource.webpackJsonp.../../../../ng2-smart-table/lib/data-source/local/local.data-source.js.LocalDataSource.getElements ( http://localhost:4200 /1.chunk.js:22280:30 ) 在 LocalDataSource.webpackJsonp.../../../../ng2-smart-table/lib/data-source/data-source.js.DataSource.emitOnChanged ( http://localhost:4200/1.chunk.js:22185:14 ) 在 LocalDataSource.webpackJsonp.../../../../ng2-smart-table/lib/data-source/data-source .js.DataSource.load ( http://localhost:4200/1.chunk.js:22105:14 ) 在 LocalDataSource.webpackJsonp.../../../../ng2-smart-table/lib/数据源/local/local.data-source.js.LocalDataSource.load ( http://localhost:4200/1.chunk.js:22243:38 )