2016-12-09 63 views
0

Ionic 2.0.0-beta.20からIonic 2.0.0-rc.3this guideを使用してアプリをアップグレードしています。イオン2のプロバイダ

私はRatingServiceと呼ばれるproviderに関する問題があります。少し混乱しています。誰でも手伝っていただければ幸いです。

問題は、私はapp.module.tsに次のエラーを取得します。

[ts] Argument of type '{ declarations: any[]; imports: ModuleWithProviders[]; bootstrap: typeof IonicApp[]; entryCompone...' is not assignable to parameter of type 'NgModule'. 
     Types of property 'providers' are incompatible. 
     Type '{ provide: typeof ErrorHandler; useClass: typeof IonicErrorHandler; RatingService: typeof RatingS...' is not assignable to type 'Provider[]'. 
      Type '{ provide: typeof ErrorHandler; useClass: typeof IonicErrorHandler; RatingService: typeof RatingS...' is not assignable to type 'Provider'. 
      Object literal may only specify known properties, and 'RatingService' does not exist in type 'Provider'. 

は、私は、各providerためprovide:useClass:を利用するために必要があると思うが、私は、これらの値がどうあるべきかわからないんだけど?

コード

app.module.ts

import { RatingService } from '../pages/service/ratingService'; 
    ... 
    providers: [{ provide: ErrorHandler, 
    useClass: IonicErrorHandler, 
    RatingService, 
    JobService, 
    UtilityService, 
    ... 

ratingService.ts

import { Injectable, Inject } from "@angular/core"; 
import { RatingModel } from '../model/RatingModel'; 
import { NavController } from 'ionic-angular'; 
import { Http, Headers } from "@angular/http" 
import { ParentService } from "../service/parentService"; 
import 'rxjs/add/operator/map'; 

@Injectable() 
export class RatingService extends ParentService { 

    public BASE_URI: String = super.getBaseUrl()+'/rating'; 

    public http: Http = null; 

    constructor(@Inject(Http) http: Http) { 
     super(); 
     this.http = http; 
    } 

    getRatingRange(firstResult: number, maxResults: number): Promise<RatingModel[]> { 
     return new Promise<RatingModel[]>(resolve => { 
      this.getRatingRangeHttpCall(firstResult, maxResults).subscribe(
       data => { 
        var ratingModels: RatingModel[] = []; 
        for (var index = 0; index < data.length; index++) { 
         var element = data[index]; 
         ratingModels.push(element); 
        } 
        resolve(ratingModels); 
       }, 
       error => alert('RatingRangeDataPromise(' + firstResult + ', ' + maxResults + ') Data not available. Please try again.\n' + error), 
       () => { 
       }); 
     }); 
    } 

    getRatingForJobRange(firstResult: number, maxResults: number, jobId: number): Promise<RatingModel[]> { 
     return new Promise<RatingModel[]>(resolve => { 
      this.getRatingRangeForJobHttpCall(firstResult, maxResults, jobId).subscribe(
       data => { 
        var ratingModels: RatingModel[] = []; 
        for (var index = 0; index < data.length; index++) { 
         var element = data[index]; 
         ratingModels.push(element); 
        } 
        resolve(ratingModels); 
       }, 
       error => alert('RatingForJobRange(' + firstResult + ', ' + maxResults + ', ' + jobId + ') Data not available. Please try again.\n' + error), 
       () => { 
       }); 
     }); 
    } 

    saveRating(ratingModel: RatingModel): Promise<RatingModel> { 
     return new Promise<RatingModel>(resolve => { 
      this.saveRatingHttpCall(ratingModel).subscribe(
       data => { 
        resolve(data); 
       }, 
       error => alert('Save Unsuccesfull.\n' + error), 
       () => { 

       }); 
     }); 
    } 

    getRating(id: number): Promise<RatingModel> { 
     return new Promise<RatingModel>(resolve => { 
      this.getRatingHttpCall(id).subscribe(
       data => { 
        resolve(data); 
       }, 
       error => alert('getRating Data not available. Please try again.\n' + error), 
       () => { 
        //console.log("Finished getRating"); 
       }); 
     }); 
    } 

    public getRatingRangeHttpCall(firstResult: number, maxResults: number) { 
     return this.http.get(this.BASE_URI + '/list/range/' + firstResult + '/' + maxResults) 
      .map(res => res.json()); 
    } 

    public getRatingRangeForJobHttpCall(firstResult: number, maxResults: number, jobId: number) { 
     return this.http.get(this.BASE_URI + '/list/range/' + firstResult + '/' + maxResults + '/' + jobId) 
      .map(res => res.json()); 
    } 

    public saveRatingHttpCall(ratingModel: RatingModel) { 
     var headers = new Headers(); 
     headers.append('Accept', 'application/json'); 
     headers.append('Content-Type', 'application/json'); 
     return this.http.post(this.BASE_URI + '/save', ratingModel, { 
      headers: headers 
     }) 
      .map(res => res.json()); 
    } 

    public getRatingHttpCall(id: number) { 
     return this.http.get(this.BASE_URI + '/list/' + id) 
      .map(res => res.json()); 
    } 

} 

parentService.ts

import { Injectable, Inject } from "@angular/core"; 

@Injectable() 
export class ParentService { 

    public PARENT_BASE_URI: string = 'http://localhost:8080/jbosswildfly'; 
    //public PARENT_BASE_URI: string = 'http://jbosswildfly-easypeasy.rhcloud.com'; 

    constructor() { 

    } 

    public getBaseUrl(): string { 
     return this.PARENT_BASE_URI; 
    } 
} 

UPDATE

私は、次のコードを変更している、私はそれが動作するかどうかを確認するためにそれをテストします:

providers: [ 
    { provide: ErrorHandler, useClass: IonicErrorHandler}, 
    { provide: RatingService, useClass: RatingService}, 
    { provide: JobService, useClass: JobService}, 
    { provide: UtilityService, useClass: UtilityService} 
    ] 
+0

'{provide:.. useClass..'}を'} 'で閉じてはいけませんか? (わからない、このようにmyseflを使用していない – Ivaro18

答えて

4

は次のようになります。

providers: [{ provide: ErrorHandler, 
useClass: IonicErrorHandler}, 
RatingService, 
JobService, 
UtilityService, 
0

あなたは誤って使用した場合にもこのエラーが発生する可能性があります

私はそれが他の誰かと同じ欲求不満を節約することを期待して、この答えを追加しているので、私は2時間を要したタイプミス代わり

import { RatingService } from '../pages/service/ratingService'; 

の0

import RatingService from '../pages/service/ratingService';