Angular Signal Generators
    Preparing search index...
    • Resolves a value once a ResourceRef from functions like httpResource or resource are no longer loading. Rejects if the resource error signal becomes truthy. Will resolve immediately if the resource is already loaded, or reject immediately if the resource already has an error.

      Type Parameters

      • TResource extends ResourceRef<unknown>

      Parameters

      • resource: TResource

        The resource reference to convert into a promise.

      • Optionalinjector: Injector

        Optional injector to use for the internal effect. Only needed if the resource signals depend on injection.

      Returns Promise<ResourceRefValue<TResource>>

      A promise that resolves with the resource value once loading completes, or rejects if an error occurs.

      const userResource = httpResource<User>(() => `/api/users/${userId()}`);
      const user = await resourceRefToPromise(userResource, this.injector);
      console.log('Loaded user', user);