I am facing an issue while setting up a service on Angular version 7. The problem arises with the res.json()
method, throwing an error stating
Property 'json' does not exist on type 'Object'
. Below is my service's code:
import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Observable} from "rxjs";
import 'rxjs/add/operator/map';
import { map } from 'rxjs/operators';
import {
SVCParameters,
SVCResult
} from "./types";
const SERVER_URL: string = 'api/';
@Injectable()
export class IrisService {
constructor(private http: HttpClient) {
}
public trainModel(svcParameters: SVCParameters): Observable<SVCResult> {
return this.http.post(`${SERVER_URL}train`, svcParameters).pipe(map(res => res.json()));
}
}
Below is the code snippet from my types.ts file defining the classes for SVC parameters and results:
export class SVCParameters {
C: number = 2.0;
}
export class SVCResult{
accuracy: number;
}