error TS2339: Property 'subscribe' does not exist on type '{}'. Service file :
import { HttpClient, HttpHeaders,HttpResponse } from '@angular/common/http';
import { Person } from './person';
import { Injectable } from '@angular/core';
import { throwError } from 'rxjs';
import 'rxjs/add/operator/map'
import { map } from "rxjs/operators";
@Injectable({
providedIn: 'root'
})
export class ApiService {
baseURL: string = "http://localhost:3000/api/persons/";
constructor(private http: HttpClient) {
}
addPerson(id,name)
{
var obj={};
var headers = new Headers();
headers.append('Content-Type', 'application/json');
let formData:FormData = new FormData();
formData.append('id',id);
formData.append('name',name);
this.http.post(this.baseURL + "addPerson?token",formData).pipe(map(data => {
alert(data);
return data;
}));
return obj;
}
}
Component file :
import { Component, OnInit } from '@angular/core';
import { ApiService } from './api.service';
import { Person } from './person';
import { Observable } from 'rxjs';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
title = 'httppost';
people:Person[]=[];
person = new Person();
formData:any = {};
constructor(private apiService:ApiService) {
this.formData.ID =""; this.formData.Name= "";
}
ngOnInit() {
}
addPerson() {
this.apiService.addPerson(this.formData.ID,this.formData.Name).subscribe(data => {
console.log(data)
})
}
}
have service file in which i have to call my api to get the api's and when i am going to subscribe the method in the other class where i am calling that service method then its showing the error that the property "subscribe " does not exist on type {}