Angular (IONIC) – API REST Symfony – Cannot read property ‘getInfos’ of undefined

I am working on a project with a teammate where I can read an API from Angular.
Right now, we both work on our project version but in the end, I would send the part to him for integration. We are noobs on Git Project Management.

I created endpoints from Symfony.
From there, I can read the endpoint with a GET and a POST (with Postman too).

I suspected it was about CORS issue but apparently not, i wrote as my teammate on my controller and he doesn’t have any mistake:

namespace AppController;

header("Access-Control-Allow-Origin : *");

But as soon I am on my Front part (Angular), I get an error message: "Cannot read property 'getInfos' of undefined"

In my, I wrote these lines:

  ngOnInit() {
    try {
      return this.infosService.getAllInfos()
          .subscribe(data => this.infos = data);
    } catch(e) {
      console.log("TEST KO");

In my console, I get the message "Test KO".

In my infos.service.ts file, I got these lines to get the datas but only call getAllInfos in this example:


  constructor(private _http: HttpClient) { }
    getInfos() {
        return this._http.get<Infos[]>(this.apiUrl);

I put my code on stackblitz, but it missing of course, the API part, but cannot see what I messed up.

Should I use another approach? I found other tutorials indicating to create a REST service.
In the end, I should merge my part with my teammate and I am afraid using different approach would bug the project.

Here’s a draft on stackblitz, if that helps.

Thanks guys for the input, just a nudge on the right direction would help me a lot.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *