我正在尝试在离子3角度4应用程序中实现ngx-datatable时,val.slice不是函数错误。请找到下面的代码部分
app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { HttpModule } from '@angular/http';
import { HttpClientModule } from '@angular/common/http';
import { HeaderMenuComponent } from '../components/header-menu/header-menu';
import { NgxDatatableModule } from '@swimlane/ngx-datatable';
import { MyApp } from './app.component';
import { TodolistPage } from '../pages/todolist/todolist';
import { AuthServiceProvider } from '../providers/auth-service';
@NgModule({
declarations: [
MyApp,
TodolistPage,
SignupPage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
HttpModule,
HttpClientModule,
NgxDatatableModule
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
TodolistPage
],
providers: [
{provide: ErrorHandler, useClass: IonicErrorHandler},
AuthServiceProvider,
]
})
export class AppModule {}
待办事项-list.html:
<ion-navbar>
<ion-title>To-do List</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<div>
<ngx-datatable
[sortType]="'multi'"
[headerHeight]="50"
[footerHeight]="50"
[rowHeight]="50"
[rows]="rows"
[columns]="columns"
[columnMode]="'force'"
[limit]="10">
</ngx-datatable>
</div>
</ion-content>
待办事项-list.ts:
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { AuthServiceProvider } from '../../providers/auth-service';
@IonicPage()
@Component({
selector: 'page-todolist',
templateUrl: 'todolist.html',
})
export class TodolistPage {
public columns: any;
public rows: any;
public error: any;
constructor(public navCtrl: NavController, public navParams: NavParams,public authService: AuthServiceProvider) {
this.columns = [
{ prop : 'name' },
{ name : 'ID' },
{ name : 'Username'},
{ name : 'Email ID'}
];
this.getUsers(); //runs on page load
}
getUsers() {
this.authService.getData('getFeed').then((result) => {
//console.log(result);
this.rows = result;
},(err) => {
this.error =err;
alert(this.error);
});
}
}
我的服务文件来获取数据:
AUTH-service.ts:
import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http';
import 'rxjs/add/operator/map';
import { Header } from 'ionic-angular/components/toolbar/toolbar-header';
let apiUrl = "http://localhost/PHP-Rest/api/";
@Injectable()
export class AuthServiceProvider {
constructor(public http: Http) {
console.log('Hello AuthServiceProvider Provider');
}
getData(type){
return new Promise((resolve, reject) => {
let headers = new Headers();
this.http.get(apiUrl+type,{headers: headers}).subscribe(res => {
resolve(res.json());
}, (err) => {
reject(err);
});
})
}
}
对于这个程序,我得到如下的JSON输出,
我没有发现任何错误,我是离线角度的新手。请帮我解决这个问题。
提前致谢。
val.slice不是离子3角度4应用中的函数错误
答案 0 :(得分:3)
通常,当您尝试在表中呈现的数据不是像Array这样的“可迭代”类型时,您会看到错误。
所以在你的情况下你有对象{feedData:[...对象数组......]}
你需要它:[...对象数组......]