W3cubDocs

/Angular

ResourceRef

A WritableResource created through the resource function.

API

interface ResourceRef<T> extends WritableResource<T> {
  hasValue(this: T extends undefined ? this : never): this is ResourceRef<Exclude<T, undefined>>;
  hasValue(): boolean;
  destroy(): void;
  readonly override value: WritableSignal<T>;
  override set(value: T): void;
  override update(updater: (value: T) => T): void;
  override asReadonly(): Resource<T>;
  override reload(): boolean;
  readonly override status: Signal<ResourceStatus>;
  readonly override error: Signal<Error | undefined>;
  readonly override isLoading: Signal<boolean>;
  readonly override snapshot: Signal<ResourceSnapshot<T>>;
}

hasValue

this is ResourceRef<Exclude<T, undefined>>
@paramthisT extends undefined ? this : never
@returnsthis is ResourceRef<Exclude<T, undefined>>

hasValue

boolean
@returnsboolean

destroy

void

Manually destroy the resource, which cancels pending requests and returns it to idle state.

@returnsvoid

value

WritableSignal<T>

set

void

Convenience wrapper for value.set.

@paramvalueT
@returnsvoid

update

void

Convenience wrapper for value.update.

@paramupdater(value: T) => T
@returnsvoid

asReadonly

Resource<T>
@returnsResource<T>

reload

boolean

Instructs the resource to re-load any asynchronous dependency it may have.

Note that the resource will not enter its reloading state until the actual backend request is made.

@returnsboolean

status

Signal<ResourceStatus>

The current status of the Resource, which describes what the resource is currently doing and what can be expected of its value.

error

Signal<Error | undefined>

When in the error state, this returns the last known error from the Resource.

isLoading

Signal<boolean>

Whether this resource is loading a new value (or reloading the existing one).

snapshot

Signal<ResourceSnapshot<T>>

The current state of this resource, represented as a ResourceSnapshot.

Super-powered by Google ©2010–2025.
Code licensed under an MIT-style License. Documentation licensed under CC BY 4.0.
https://angular.dev/api/core/ResourceRef