Looking for help with integrating Angular and SpringREST to fetch data from the backend? Here's my situation: I need to retrieve a JSON string from the backend using a POST request, send it to my site's hosted link, and display it on the user interface. However, I'm unsure about the postMethod function in dataservice.ts.
I tried researching on StackOverflow and found some code that didn't work for me:
Component.ts
import { MyDataService } from './services/my-data.service';
constructor(private posting: MyDataService) {}
ngOnInit() {
this.posting.postMethod().subscribe(
(response => {
console.log(response)
}));
}
}
Data-service.ts
@Injectable()
export class MyDataService {
constructor(private http: Http){}
postMethod(model: any ) {
return this.http.post("http ://", model)
.map(res => res.json());
}
}