-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathmutation-page.component.ts
41 lines (35 loc) · 1.27 KB
/
mutation-page.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { CommonModule } from '@angular/common';
import { injectIsMutating } from '@ngneat/query';
import { FormsModule } from '@angular/forms';
import { TodosService } from '../services/todos.service';
import { TabsComponent } from '../ui/query-tabs/tabs.component';
import { TabComponent } from '../ui/query-tab/tab.component';
@Component({
selector: 'query-mutation-page',
standalone: true,
imports: [CommonModule, FormsModule, TabsComponent, TabComponent],
templateUrl: './mutation-page.component.html',
styles: [],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MutationPageComponent {
#useIsMutating = injectIsMutating();
#todoService = inject(TodosService);
public addTodoMutationsActive = this.#useIsMutating().toSignal();
public addTodo = this.#todoService.addTodo();
public addTodoSignalResult = this.addTodo.result;
public newTodo = '';
public onAddTodo(title: string) {
this.addTodo.mutate({ title, showError: false });
this.newTodo = '';
}
public onAddTodoWithError(title: string) {
this.addTodo.mutate({ title, showError: true });
this.newTodo = '';
}
public onResetMutation() {
this.addTodo.reset();
this.newTodo = '';
}
}