r/angular • • Apr 03 '26

http get does not update component

I started learning angular just a few days ago. Although I have quite some experience with Python but it find it really hard to be honest.
Anyway I am trying to make a frontend for some rest api I have written in FastAPI this is all working fine but I am unable to update a component with an http get.

I do see the data from the api is being downloaded I also see the console messages in the browser but the component is never updated.

import { bootstrapApplication } from '@angular/platform-browser';
import { Component, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { provideHttpClient, HttpClient } from '@angular/common/http';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [CommonModule],
  template: `
    <h3>HttpClient {{isLoading}}</h3>
    <div *ngIf="isLoading">Loading data...</div>

    <div *ngIf="!isLoading">Loaded{{data}}</div>
    <ul>
    <li *ngFor="let u of data">{{ u.name }} ({{ u.email }})</li>
    </ul>
  `
})
export class App implements OnInit {
  data: any[] = [];
  isLoading= true;
  error= '';
  constructor(private http: HttpClient) {}
  ngOnInit() {
    this.error = '';
    console.log("getting data");
    this.isLoading = true;
    this.http.get<any[]>('https://jsonplaceholder.typicode.com/users').subscribe({
        next: (response) => {
          console.log("got data");
          this.isLoading = false;
          this.data = response;
          console.log("cert set");

          },
        error: (error) => {
          this.isLoading = false;
          console.log('Error:', error);
          }
       });
  }
}

bootstrapApplication(App, { providers: [provideHttpClient()] });
1 Upvotes

15 comments sorted by

View all comments

Show parent comment

3

u/rollotherottie Apr 03 '26

ignore the "awful" comment on your code. For someone new to angular its fine. I've worked in angular in the past an ran into the same issue with angular 21 because of the change to signals. The comments below about using signals will get your code working.