2017-11-27 6 views
1

의 매개 변수에 할당 할 수없는타이프는 '(오류 : 어떤) => 무효'유형의 인수는 :</p> <pre><code>private getJSON(): Observable<any> { return this.http.get('./reportNav-NEW.json') .map((res:any)=> res.json()) .catch((error:any) => console.log(error)); } </code></pre> <p>오류가 나에게 제공 : 코드에 따라 유형

그것은에서 일어나는

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 thanks! – 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합니다)