کافه انگولار
import { Component, signal } from '@angular/core';
import { httpResource } from '@angular/common/http';
@Component({
selector: 'app-user',
template: `
@if (user.isLoading()) {
<p>Loading…</p>
} @else if (user.hasValue()) {
<h1>{{ user.value().name }}</h1>
}
`
})
export class UserComponent {
userId = signal(1);
// Re-fetches automatically whenever userId changes.
user = httpResource<User>(() => `/api/users/${this.userId()}`);
}
استفاده از httpResource بسیار جذاب و کارامد هست 🥳
#angularsignal
#angularcafe
1 · 125 ·