问题:阅读Json并创建一个列表(Ionic)

时间:2017-07-25 20:24:01

标签: angularjs json mobile ionic-framework ionic2

我想创建一个列表但是当读取Json时会出现此错误 我该如何解决?

   import { Injectable } from '@angular/core';
   import { Http } from '@angular/http';
   import 'rxjs/add/operator/map';
   import 'rxjs/add/operator/do';

   /*
    Generated class for the KpisProvider provider.

   See https://angular.io/docs/ts/latest/guide/dependency-injection.html
   for more info on providers and Angular DI.
   */
   @Injectable()
   export class KpisProvider {

        private url: string = 'https://private-anon-3cb8931ec8-kpisapi1.apiary-mock.com/api/Projects';

       constructor(private http: Http) {
         console.log('Hello KpisProvider Provider');
       }

       getProjects(){
         return this.http.get(this.url)
.        .do((res: Response) => console.log(res))
         .map((res: Response) => res.json());
       }

   }

错误是:

类型的参数'(res:Response)=>空隙'不能分配给类型的参数             ' PartialObserver&#39 ;.输入'(res:Response)=>空隙'不能分配给类型             ' CompletionObserver&#39 ;.财产'完成'类型'中缺少(res:Response)=>空隙'

  L22:  return this.http.get(this.url)
  L23:  .do((res : Response) => console.log(res))
  L24:  .map((res : Response) => res.json());

1 个答案:

答案 0 :(得分:0)

你有额外的时间吗?在你正在运行的查询中?

return this._http.get(this.url)
    .map((res: Response) => res.json())

    .catch(this._errorHandler);

订阅http呼叫的方法可以注销结果