MCPcopy Create free account
hub / github.com/angular/angular / SignalFormsComponent

Class SignalFormsComponent

packages/core/test/bundling/forms_signals/main.ts:13–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11import {bootstrapApplication} from '@angular/platform-browser';
12
13@Component({
14 selector: 'app-signal-forms',
15 imports: [FormField],
16 template: `
17 <div>
18 First Name:
19 <input type="text" [formField]="profileForm.firstName" />
20 </div>
21 <div>
22 Last Name:
23 <input type="text" [formField]="profileForm.lastName" />
24 </div>
25 <div>
26 Subscribe:
27 <input type="checkbox" [formField]="profileForm.subscribed" />
28 </div>
29 <div>
30 Disabled:
31 <input [formField]="profileForm.disabledInput" />
32 </div>
33 @for (address of profileForm.addresses; track address) {
34 <div>City: <input [formField]="address.city" /></div>
35 }
36 <button (click)="addCity()">Add City</button>
37 `,
38})
39class SignalFormsComponent {
40 readonly model = signal({
41 firstName: '',
42 lastName: '',
43 subscribed: false,
44 disabledInput: '',
45 addresses: [{city: ''}],
46 });
47
48 readonly profileForm = form(this.model, (p) => {
49 required(p.firstName);
50 disabled(p.disabledInput);
51 });
52
53 addCity(): void {
54 this.model.update((m) => ({
55 ...m,
56 addresses: [...m.addresses, {city: ''}],
57 }));
58 }
59}
60
61@Component({
62 selector: 'app-root',

Callers

nothing calls this directly

Calls 5

ComponentInterface · 0.90
signalFunction · 0.90
formFunction · 0.90
requiredFunction · 0.90
disabledFunction · 0.90

Tested by

no test coverage detected