Created
March 3, 2025 13:10
-
-
Save Armenvardanyan95/b1db5e1f0212a4b9774fe0814e722e8d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
template: ` | |
@if (todos.hasValue()) { | |
<select [(ngModel)]="todoId"> | |
@for (todo of todos.value(); track todo.id) { | |
<option [value]="todo.id">{{ todo.title }}</option> | |
} | |
</select> | |
} | |
@if (todo.hasValue()) { | |
<div> | |
<h1>{{ todo.value().title }}</h1> | |
<p>{{ todo.value().completed }}</p> | |
</div> | |
} | |
@if (todos.isLoading() || todo.isLoading()) { | |
<div>Loading...</div> | |
} | |
@if (todos.error()) { | |
<!-- retry on error --> | |
<button (click)="todos.reload()">Retry</button> | |
} | |
`, | |
imports: [FormsModule], | |
}) | |
export class HttpResourceComponent { | |
todoId = signal<number | null>(1); | |
todos = httpResource<Todo[]>( | |
() => `https://jsonplaceholder.typicode.com/todos`, | |
); | |
todo = httpResource<Todo>( | |
() => `https://jsonplaceholder.typicode.com/todos/${this.todoId()}`, | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment