2016-10-04 99 views
0

這是我使用這個服務類如下角JS2 HTTP GET錯誤

@Injectable() 
export class LoginService{ 
    baseUrl:string; 
    token:string; 
    constructor(private _http: Http, private _loggerService: LoggerService) { 
     this.baseUrl = "http://localhost:49454"; 
     this.token = ''; 
    } 

    private extractData(res: Response) { 
     let body = res.json(); 
     console.log('-------------------------------------------') 
     console.log(body); 
     console.log('-------------------------------------------') 
     return body.data || { }; 
    } 

    private handleError (error: any) { 

     console.log('-------------------------------------------') 
     console.log('XXX'); 
     console.log('-------------------------------------------') 
     let errMsg = (error.message) ? error.message : 
      error.status ? `${error.status} - ${error.statusText}` : 'Server error'; 
     console.error(errMsg); 
     return Observable.throw(errMsg); 
    } 

    public pingpong() { 

     var test = 'http://localhost:33345/Apple/Bear'; 

     var sd = this._http.get(test) 
      .map(this.extractData) 
      .catch(this.handleError); 



     return sd; 

    } 

} 

庵調用乒乓球()從TS方法來發送GET請求得到

Exception: TypeError: 'caller' and 'arguments' are restricted function properties and cannot be accessed in this context 

庵錯誤組件

爲什麼我在這個特定的類中得到上述錯誤?

回答

0

發生這種情況是因爲我沒有訂閱請求,因爲它是可觀察的並且在此之前嘗試訪問它。