I am trying to copy the working code from Plnkr to my machine and it's showing error in the VisualStudio.
Currently I am using @angular "^2.4.5" and rxjs "^5.2.0"
The error is saying that
Argument of type '(error: any) => void' is not assignable to parameter of type '(err: any, caught: Observable) => ObservableInput<{}>'.
You can see in my following script that I copied exactly similar to the Plnkr code and imported 'catch' operator. However, it's not working and showing the above error in getStudentCourse2() method.
If I removed catch operator and changed the code like the one in getStudentCourse() method, it works and I can see the result.
student.service.ts
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/of';
@Injectable()
export class StudentService {
private http: Http;
constructor(http: Http) {
this.http = http;
}
getStudentCourse(): Observable<IStudentCourse> {
return this.http.get('/api/student/getstudentcourse').map(result => {
return result.json() as IStudentCourse;
}, error => console.log('Could not load data in service.'));
}
getStudentCourse2(): Observable<IStudentCourse> {
return this.http.get('https://58cff77fe1a0d412002e446d.mockapi.io/api/student/getstudentcourse/2').map(result => {
return result.json() as IStudentCourse;
}).catch(error => console.log('Could not load data in service.'));
}
}
export interface IStudentCourse {
refNo: string;
student: string;
offeringName: string;
offeringID: number;
}
I couldn't find out why 'Catch' operator is not working in my code like 'Plnkr'. Could you guys please help me with this issue? Thanks.
