#Having a hard time with httpResource()

4 messages · Page 1 of 1 (latest)

valid steppe
#

I am new to Angular and I tried to use httpResource() to test by using the below method. But I am not able to display the result in UI. Please can somebody guide me?

import { JsonPipe } from "@angular/common";
import { httpResource, provideHttpClient } from "@angular/common/http";
import { Component } from "@angular/core";
import { bootstrapApplication } from "@angular/platform-browser";

export interface User {
  name: string;
  email: string;
}

@Component({
  selector: "app-root",
  imports: [JsonPipe],
  template: `
    <ul>
      @for (user of usersResource | json ; track user) {
      <li>{{ user }}</li>
      }
    </ul>
  `,
})
export class App {
  usersResource = httpResource<User[]>(
    "https://jsonplaceholder.typicode.com/users"
  );
}

bootstrapApplication(App, {
  providers: [provideHttpClient()],
});
wheat shale
#

And do not use json pipe

valid steppe
#

thanks. It's solved the issue.