2017-11-27 6 views
1

のパラメータに割り当て可能ではありません。活字体:型の引数は、 '(エラー:任意の)=>ボイドは' 次のコードタイプ

private getJSON(): Observable<any> { 
    return this.http.get('./reportNav-NEW.json') 
     .map((res:any)=> res.json()) 
     .catch((error:any) => console.log(error)); 
    } 

エラーは私を与える:

Argument of type '(error: any) => void' is not assignable to parameter of type '(err: any, caught: Observable) => ObservableInput<{}>'. Type 'void' is not assignable to type 'ObservableInput<{}>'.

それはで起こります.catch((error:any) => console.log(error));

+0

@Carcigenicate私はconsole.logを読んでコンソールに記録するだけでなく、リターン機能も提供しています。この問題の正解の最後のコメントで説明されています。https://stackoverflow.com/questions/39406043/how-to-fetch-json-file-in-angular-2 – ezzzCash

+0

@trevorありがとう! – ezzzCash

答えて

0

これは私のために働いた

private getJSON(): Observable<any> { 
    console.log(document.location.href); 
    return this.http.get('...') 
     .map((res:any)=> res.json()) 
     .catch((error:any) => { 
     return Observable.throw(error); 
     }) 
    } 
(おかげで、コメントに@trevorします)
関連する問題