2017-03-10 2 views
2

임 'MyAddressConfig'가 http.get에있는 문자열을 반환하는 데 약간의 문제가 있습니다. Ionic2 Storage에서 데이터를 가져옵니다. 문제는 내가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

고마워요

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

안녕하세요. –

관련 문제