我正在ionic2中构建应用程序,每当我加载数据时都会收到此错误
无法阅读财产' map'未定义的
这是我的组件
export class TrackingcenterPage implements OnInit {
constructor(public _navCtrl: NavController, public navParams: NavParams,
private _truckService:TruckService) {
}
ngOnInit() { // tried using OnInit but ionic complains and needs ngOnInit
this.onGettrucks();
}
onGettrucks() {
return this._truckService.getTrucks()
.subscribe(res=>console.log(res), err=>console.log(err))
}
}
我的卡车服务
@Injectable()
export class TruckService {
trucksurl = this._domaindetails.getUrl() +"/rest/v1/truck/";
getTrucks():Observable<any> {
return this._httpClient.get(this.trucksurl+"trucks")
.map(res=>res.json().data)
}
在我导入的卡车服务中
import 'rxjs/add/operator/map';
import {Observable} from "rxjs";
我也尝试用onPageLoaded
替换OnInit事件,但它也失败了