Injects
injectWrite
Trigger mutations with loading and error states
Trigger mutations with loading and error states. The callback selects the API method (no parentheses).
Basic Usage
@Component({
selector: "app-create-user",
template: `
<form (ngSubmit)="handleSubmit()">
<button [disabled]="createUser.loading()">
{{ createUser.loading() ? "Creating..." : "Create User" }}
</button>
</form>
`,
})
export class CreateUserComponent {
createUser = injectWrite((api) => api("users").POST);
async handleSubmit() {
const result = await this.createUser.trigger({ body: formData });
if (result.data) {
console.log("Created:", result.data);
}
}
}With Invalidation
createPost = injectWrite((api) => api("posts").POST);
await createPost.trigger({
body: { title: "New Post", content: "..." },
invalidate: ["posts"],
});Returns
| Property | Type | Description |
|---|---|---|
trigger | (options) => Promise | Execute the mutation |
data | Signal<TData | undefined> | Response data |
error | Signal<TError | undefined> | Error if request failed |
loading | Signal<boolean> | True while mutation is in progress |
abort | () => void | Abort current request |
input | TriggerOptions | undefined | The last trigger input |
meta | Signal<PluginResults> | Plugin-provided metadata |
Trigger Options
| Option | Type | Description |
|---|---|---|
body | TBody | Request body |
query | TQuery | Query parameters |
params | Record<string, string | number> | Path parameters |
| + plugin options | - | Options from installed plugins |