2017-03-10 11 views
2

私はhttp.getの文字列を返すために 'MyAddressConfig'を取得するのに少し問題があります。それはIonic2ストレージからデータを取得します。問題は、私はObservable http.getで購読する

が任意のアイデアhttp://localhost:0000/[object%20Object]my/path?&tst=1 404(見つかりません)

をGET!取得しておくことですかMyAddressConfig

GetDataFromStorage: Observable<any> = 

Observable.fromPromise(
    Promise.all([ 
     this.ionicStorage_.get('MyRestIPAddress'), // 'localhost' 
     this.ionicStorage_.get('MyRestIPPort'), // '0000' 
    ]) 
     .then(([val1, val2]) => { 
      this.MyRestIPAddress = val1; 
      this.MyIPPort = val2; 
      return [val1, val2]; 
     }) 
); 

GetRestAddress() { 
     return this.GetDataFromStorage.subscribe(([val1, val2]) => { // 'localhost','0000' 
      let RestAddress = 'http://' + val1 + ':' + val2 + '/rest/'; 
      console.log(RestAddress); 
      return RestAddress; // 'http://localhost:0000/rest/' 
     }); 
    } 

たMyService

-thanks

getStoresSummaryResults(): Observable<MyTypeClass> { 
     let MyConfig: MyAddressConfig; 
     MyConfig = new MyAddressConfig(this.ionicStorage_); 

     return this.http_.get(MyConfig.GetRestAddress() + 'my/path?&tst=1') 
      .map(res => res.json()) 
      .catch(this.handleError); 
    } 

答えて

6

あなたMyConfig.GetRestAddress()文字列を返しません、それはオブジェクトを返します。 [object%20object]MyConfig.GetRestAddress() because your object is parsed to a string

です。これはGetRestAddress()がサブスクリプションを返すためです。このようなものがあなたが望むものです:

GetRestAddress() { //return the url as Observable 
    return this.GetDataFromStorage.switchMap(([val1, val2]) => { 
     let RestAddress = 'http://' + val1 + ':' + val2 + '/rest/'; 
     return Observable.of(RestAddress); // 'http://localhost:0000/rest/' 
    }); 
} 


getStoresSummaryResults(): Observable<MyTypeClass> { 
    let MyConfig: MyAddressConfig; 
    MyConfig = new MyAddressConfig(this.ionicStorage_); 

    return MyConfig.GetRestAddress() 
     .switchMap(url => this.http_.get(url + 'my/path?&tst=1') 
     .map(res => res.json()) 
     .catch(this.handleError); 
} 
+0

おかげさまで大変感謝しています。 –

関連する問題