javascript - Does the Angular resource API support adding an initial value for the resource? - Stack Overflow

admin2025-05-01  0

Suppose we first check whether a resource is not loading like this:

    @if (!countriesResource.isLoading()) {
      <ul>
        @for (
          country of countriesResource.value(); 
          track country.name.official
        ) {
          <li>{{ country.name.official }}</li>
        }
      </ul>

If the resource is not loading, however has not initiated a request yet, is there a way to provide an initial value so that countriesResource.value() resolves to an initial value?

Suppose we first check whether a resource is not loading like this:

    @if (!countriesResource.isLoading()) {
      <ul>
        @for (
          country of countriesResource.value(); 
          track country.name.official
        ) {
          <li>{{ country.name.official }}</li>
        }
      </ul>

If the resource is not loading, however has not initiated a request yet, is there a way to provide an initial value so that countriesResource.value() resolves to an initial value?

Share Improve this question asked Jan 2 at 18:38 OleOle 47.6k70 gold badges238 silver badges447 bronze badges 1
  • Related: github.com/angular/angular/issues/58840 – Ole Commented Jan 2 at 18:53
Add a comment  | 

1 Answer 1

Reset to default 2

Does the Angular resource API support adding an initial value for the resource

Today no.

But keep in mind that resource is an experimental API and the Angular team plan to have an RFC on the concept of resource in the following week.

转载请注明原文地址:http://anycun.com/QandA/1746102568a91701.html