Question Details

No question body available.

Tags

angular typescript angular21

Answers (1)

July 22, 2026 Score: 4 Rep: 67,449 Quality: Medium Completeness: 60%

Since you are using Angular 21 which is by default zoneless, we need to use signals when you want to use the variable in the DOM or View (So that the updates are reflected in the view) another reason to use signals is when the state change needs to have reactivity of updating other states, like using computed, effect, etc.

You should also simplify the API calls, by using the resource API, for example we can simplify the code using httpResource.

TS:

export class GetApi implements OnInit {
  private readonly http = inject(HttpClient);
  public todoResource = httpResource(() => https://jsonplaceholder.typicode.com/todos);
}

HTML:

@if(todoResource.error(); as error) {
   

Unknown API error

} @else if(todoResource.isLoading()) {

Loading...

} @else { @let todoList = todoResource.data();

Total: {{ todoList.length }}

{{ todoList | json }}

@for (item of todoList; track item.id) { }
User Id Title Completed
{{ item.userId }} {{ item.id }} {{ item.title }} {{ item.completed }}
}