Skip to content

Commit 40f080a

Browse files
committed
fixup! feat(@angular/cli): add initial set of signal form examples
1 parent 46a9e7d commit 40f080a

17 files changed

+120
-120
lines changed

packages/angular/cli/lib/examples/signal-forms/01-basic-signal-form.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import { Component, signal, output, ChangeDetectionStrategy } from '@angular/cor
4141
import { form, submit, Control } from '@angular/forms/signals';
4242
import { JsonPipe } from '@angular/common';
4343

44-
export interface UserProfile {
44+
export interface UserProfileData {
4545
firstName: string;
4646
lastName: string;
4747
email: string;
@@ -54,9 +54,9 @@ export interface UserProfile {
5454
changeDetection: ChangeDetectionStrategy.OnPush,
5555
})
5656
export class UserProfileComponent {
57-
readonly submitted = output<UserProfile>();
57+
readonly submitted = output<UserProfileData>();
5858

59-
profileModel = signal<UserProfile>({
59+
profileModel = signal<UserProfileData>({
6060
firstName: '',
6161
lastName: '',
6262
email: '',
@@ -115,13 +115,13 @@ The template is wrapped in a `<form>` tag with a `(submit)` event and a submit b
115115

116116
## How to Use This Example
117117

118-
The parent component imports the `UserProfile` interface and listens for the `(submitted)` event to receive the strongly-typed form data.
118+
The parent component imports the `UserProfileData` interface and listens for the `(submitted)` event to receive the strongly-typed form data.
119119

120120
```typescript
121121
// in app.component.ts
122122
import { Component } from '@angular/core';
123123
import { JsonPipe } from '@angular/common';
124-
import { UserProfileComponent, UserProfile } from './user-profile.component';
124+
import { UserProfileComponent, UserProfileData } from './user-profile.component';
125125

126126
@Component({
127127
selector: 'app-root',
@@ -137,9 +137,9 @@ import { UserProfileComponent, UserProfile } from './user-profile.component';
137137
`,
138138
})
139139
export class AppComponent {
140-
submittedData: UserProfile | null = null;
140+
submittedData: UserProfileData | null = null;
141141

142-
onProfileSubmit(data: UserProfile) {
142+
onProfileSubmit(data: UserProfileData) {
143143
this.submittedData = data;
144144
console.log('Profile data submitted:', data);
145145
}

packages/angular/cli/lib/examples/signal-forms/02-built-in-validators.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ import { form, schema, submit, Control } from '@angular/forms/signals';
4949
import { required, minLength, maxLength, min, max, email, pattern } from '@angular/forms/signals';
5050
import { JsonPipe } from '@angular/common';
5151

52-
export interface UserSettings {
52+
export interface UserSettingsData {
5353
username: string;
5454
age: number;
5555
email: string;
5656
website: string;
5757
}
5858

59-
const settingsSchema = schema<UserSettings>((form) => {
59+
const settingsSchema = schema<UserSettingsData>((form) => {
6060
required(form.username);
6161
minLength(form.username, 3);
6262
maxLength(form.username, 20);
@@ -78,9 +78,9 @@ const settingsSchema = schema<UserSettings>((form) => {
7878
changeDetection: ChangeDetectionStrategy.OnPush,
7979
})
8080
export class UserSettingsComponent {
81-
readonly submitted = output<UserSettings>();
81+
readonly submitted = output<UserSettingsData>();
8282

83-
settingsModel = signal<UserSettings>({
83+
settingsModel = signal<UserSettingsData>({
8484
username: '',
8585
age: 18,
8686
email: '',
@@ -183,7 +183,7 @@ The parent component listens for the `(submitted)` event to receive the validate
183183
// in app.component.ts
184184
import { Component } from '@angular/core';
185185
import { JsonPipe } from '@angular/common';
186-
import { UserSettingsComponent, UserSettings } from './user-settings.component';
186+
import { UserSettingsComponent, UserSettingsData } from './user-settings.component';
187187

188188
@Component({
189189
selector: 'app-root',
@@ -199,9 +199,9 @@ import { UserSettingsComponent, UserSettings } from './user-settings.component';
199199
`,
200200
})
201201
export class AppComponent {
202-
submittedData: UserSettings | null = null;
202+
submittedData: UserSettingsData | null = null;
203203

204-
onFormSubmit(data: UserSettings) {
204+
onFormSubmit(data: UserSettingsData) {
205205
this.submittedData = data;
206206
console.log('Settings data submitted:', data);
207207
}

packages/angular/cli/lib/examples/signal-forms/03-cross-field-validation.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ import {
5454
} from '@angular/forms/signals';
5555
import { JsonPipe } from '@angular/common';
5656

57-
export interface PasswordForm {
57+
export interface PasswordData {
5858
password: string;
5959
confirmPassword: string;
6060
}
6161

62-
const passwordSchema = schema<PasswordForm>((passwordForm) => {
62+
const passwordSchema = schema<PasswordData>((passwordForm) => {
6363
validate(passwordForm.password, ({ value }) => {
6464
if (value() === '') return requiredError();
6565
if (value().length < 8) return minLengthError(8);
@@ -81,9 +81,9 @@ const passwordSchema = schema<PasswordForm>((passwordForm) => {
8181
changeDetection: ChangeDetectionStrategy.OnPush,
8282
})
8383
export class PasswordFormComponent {
84-
readonly submitted = output<PasswordForm>();
84+
readonly submitted = output<PasswordData>();
8585

86-
passwordModel = signal<PasswordForm>({
86+
passwordModel = signal<PasswordData>({
8787
password: '',
8888
confirmPassword: '',
8989
});
@@ -152,7 +152,7 @@ The parent component listens for the `(submitted)` event and receives the strong
152152
// in app.component.ts
153153
import { Component } from '@angular/core';
154154
import { JsonPipe } from '@angular/common';
155-
import { PasswordFormComponent, PasswordForm } from './password-form.component';
155+
import { PasswordFormComponent, PasswordData } from './password-form.component';
156156

157157
@Component({
158158
selector: 'app-root',
@@ -168,9 +168,9 @@ import { PasswordFormComponent, PasswordForm } from './password-form.component';
168168
`,
169169
})
170170
export class AppComponent {
171-
submittedData: PasswordForm | null = null;
171+
submittedData: PasswordData | null = null;
172172

173-
onPasswordSubmit(data: PasswordForm) {
173+
onPasswordSubmit(data: PasswordData) {
174174
this.submittedData = data;
175175
console.log('Password data submitted:', data);
176176
}

packages/angular/cli/lib/examples/signal-forms/04-conditional-validation.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ import { Component, signal, output, ChangeDetectionStrategy } from '@angular/cor
4343
import { form, schema, applyWhen, required, submit, Control } from '@angular/forms/signals';
4444
import { JsonPipe } from '@angular/common';
4545

46-
export interface ContactForm {
46+
export interface ContactData {
4747
subscribe: boolean;
4848
email: string;
4949
}
5050

51-
const contactSchema = schema<ContactForm>((contactForm) => {
51+
const contactSchema = schema<ContactData>((contactForm) => {
5252
applyWhen(
5353
contactForm,
5454
({ value }) => value().subscribe,
@@ -63,9 +63,9 @@ const contactSchema = schema<ContactForm>((contactForm) => {
6363
changeDetection: ChangeDetectionStrategy.OnPush,
6464
})
6565
export class ContactFormComponent {
66-
readonly submitted = output<ContactForm>();
66+
readonly submitted = output<ContactData>();
6767

68-
contactModel = signal<ContactForm>({
68+
contactModel = signal<ContactData>({
6969
subscribe: false,
7070
email: '',
7171
});
@@ -122,7 +122,7 @@ The parent component listens for the `(submitted)` event and receives the strong
122122
// in app.component.ts
123123
import { Component } from '@angular/core';
124124
import { JsonPipe } from '@angular/common';
125-
import { ContactFormComponent, ContactForm } from './contact-form.component';
125+
import { ContactFormComponent, ContactData } from './contact-form.component';
126126

127127
@Component({
128128
selector: 'app-root',
@@ -138,9 +138,9 @@ import { ContactFormComponent, ContactForm } from './contact-form.component';
138138
`,
139139
})
140140
export class AppComponent {
141-
submittedData: ContactForm | null = null;
141+
submittedData: ContactData | null = null;
142142

143-
onFormSubmit(data: ContactForm) {
143+
onFormSubmit(data: ContactData) {
144144
this.submittedData = data;
145145
console.log('Contact data submitted:', data);
146146
}

packages/angular/cli/lib/examples/signal-forms/05-dynamic-field-state-hidden.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ import { Component, signal, output, ChangeDetectionStrategy } from '@angular/cor
4141
import { form, schema, hidden, required, submit, Control } from '@angular/forms/signals';
4242
import { JsonPipe } from '@angular/common';
4343

44-
export interface ContactForm {
44+
export interface ContactData {
4545
reason: 'question' | 'feedback' | 'other';
4646
otherReason: string;
4747
}
4848

49-
const contactSchema = schema<ContactForm>((form) => {
49+
const contactSchema = schema<ContactData>((form) => {
5050
// The `otherReason` field is hidden unless the reason is 'other'.
5151
hidden(form.otherReason, ({ valueOf }) => valueOf(form.reason) !== 'other');
5252

@@ -61,9 +61,9 @@ const contactSchema = schema<ContactForm>((form) => {
6161
changeDetection: ChangeDetectionStrategy.OnPush,
6262
})
6363
export class ContactFormComponent {
64-
readonly submitted = output<ContactForm>();
64+
readonly submitted = output<ContactData>();
6565

66-
contactModel = signal<ContactForm>({
66+
contactModel = signal<ContactData>({
6767
reason: 'question',
6868
otherReason: '',
6969
});
@@ -123,7 +123,7 @@ The parent component listens for the `(submitted)` event to receive the form dat
123123
// in app.component.ts
124124
import { Component } from '@angular/core';
125125
import { JsonPipe } from '@angular/common';
126-
import { ContactFormComponent, ContactForm } from './contact-form.component';
126+
import { ContactFormComponent, ContactData } from './contact-form.component';
127127

128128
@Component({
129129
selector: 'app-root',
@@ -139,9 +139,9 @@ import { ContactFormComponent, ContactForm } from './contact-form.component';
139139
`,
140140
})
141141
export class AppComponent {
142-
submittedData: ContactForm | null = null;
142+
submittedData: ContactData | null = null;
143143

144-
onFormSubmit(data: ContactForm) {
144+
onFormSubmit(data: ContactData) {
145145
this.submittedData = data;
146146
console.log('Contact data submitted:', data);
147147
}

packages/angular/cli/lib/examples/signal-forms/06-conditionally-disabling-fields.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ import { Component, signal, output, ChangeDetectionStrategy } from '@angular/cor
4141
import { form, schema, disabled, required, submit, Control } from '@angular/forms/signals';
4242
import { JsonPipe } from '@angular/common';
4343

44-
export interface PromoForm {
44+
export interface PromoData {
4545
hasPromoCode: boolean;
4646
promoCode: string;
4747
}
4848

49-
const promoSchema = schema<PromoForm>((form) => {
49+
const promoSchema = schema<PromoData>((form) => {
5050
// The `promoCode` field is disabled if `hasPromoCode` is false.
5151
disabled(form.promoCode, ({ valueOf }) => !valueOf(form.hasPromoCode));
5252

@@ -61,9 +61,9 @@ const promoSchema = schema<PromoForm>((form) => {
6161
changeDetection: ChangeDetectionStrategy.OnPush,
6262
})
6363
export class PromoFormComponent {
64-
readonly submitted = output<PromoForm>();
64+
readonly submitted = output<PromoData>();
6565

66-
promoModel = signal<PromoForm>({
66+
promoModel = signal<PromoData>({
6767
hasPromoCode: false,
6868
promoCode: '',
6969
});
@@ -123,7 +123,7 @@ The parent component listens for the `(submitted)` event to receive the form dat
123123
// in app.component.ts
124124
import { Component } from '@angular/core';
125125
import { JsonPipe } from '@angular/common';
126-
import { PromoFormComponent, PromoForm } from './promo-form.component';
126+
import { PromoFormComponent, PromoData } from './promo-form.component';
127127

128128
@Component({
129129
selector: 'app-root',
@@ -139,9 +139,9 @@ import { PromoFormComponent, PromoForm } from './promo-form.component';
139139
`,
140140
})
141141
export class AppComponent {
142-
submittedData: PromoForm | null = null;
142+
submittedData: PromoData | null = null;
143143

144-
onFormSubmit(data: PromoForm) {
144+
onFormSubmit(data: PromoData) {
145145
this.submittedData = data;
146146
console.log('Promo data submitted:', data);
147147
}

packages/angular/cli/lib/examples/signal-forms/07-dynamic-arrays.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ import { Component, signal, output, ChangeDetectionStrategy } from '@angular/cor
4242
import { form, schema, applyEach, validate, submit } from '@angular/forms/signals';
4343
import { JsonPipe } from '@angular/common';
4444

45-
export interface Question {
45+
export interface QuestionData {
4646
text: string;
4747
required: boolean;
4848
}
4949

50-
export interface SurveyForm {
50+
export interface SurveyData {
5151
title: string;
52-
questions: Question[];
52+
questions: QuestionData[];
5353
}
5454

55-
const questionSchema = schema<Question>((question) => {
55+
const questionSchema = schema<QuestionData>((question) => {
5656
validate(question.text, ({ value }) => (value() === '' ? { required: true } : null));
5757
});
5858

59-
const surveySchema = schema<SurveyForm>((survey) => {
59+
const surveySchema = schema<SurveyData>((survey) => {
6060
validate(survey.title, ({ value }) => (value() === '' ? { required: true } : null));
6161
applyEach(survey.questions, questionSchema);
6262
});
@@ -68,9 +68,9 @@ const surveySchema = schema<SurveyForm>((survey) => {
6868
changeDetection: ChangeDetectionStrategy.OnPush,
6969
})
7070
export class SurveyFormComponent {
71-
readonly submitted = output<SurveyForm>();
71+
readonly submitted = output<SurveyData>();
7272

73-
surveyModel = signal<SurveyForm>({
73+
surveyModel = signal<SurveyData>({
7474
title: '',
7575
questions: [{ text: '', required: false }],
7676
});
@@ -151,7 +151,7 @@ The parent component listens for the `(submitted)` event and receives the strong
151151
// in app.component.ts
152152
import { Component } from '@angular/core';
153153
import { JsonPipe } from '@angular/common';
154-
import { SurveyFormComponent, SurveyForm } from './survey-form.component';
154+
import { SurveyFormComponent, SurveyData } from './survey-form.component';
155155

156156
@Component({
157157
selector: 'app-root',
@@ -167,9 +167,9 @@ import { SurveyFormComponent, SurveyForm } from './survey-form.component';
167167
`,
168168
})
169169
export class AppComponent {
170-
submittedData: SurveyForm | null = null;
170+
submittedData: SurveyData | null = null;
171171

172-
onFormSubmit(data: SurveyForm) {
172+
onFormSubmit(data: SurveyData) {
173173
this.submittedData = data;
174174
console.log('Survey data submitted:', data);
175175
}

packages/angular/cli/lib/examples/signal-forms/08-custom-form-control.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ import { form, submit, Control } from '@angular/forms/signals';
7474
import { JsonPipe } from '@angular/common';
7575
import { NumericStepperComponent } from './numeric-stepper.component';
7676

77-
export interface ProductForm {
77+
export interface ProductData {
7878
name: string;
7979
quantity: number;
8080
}
@@ -86,9 +86,9 @@ export interface ProductForm {
8686
changeDetection: ChangeDetectionStrategy.OnPush,
8787
})
8888
export class ProductFormComponent {
89-
readonly submitted = output<ProductForm>();
89+
readonly submitted = output<ProductData>();
9090

91-
productModel = signal<ProductForm>({
91+
productModel = signal<ProductData>({
9292
name: 'Angular T-Shirt',
9393
quantity: 1,
9494
});
@@ -140,7 +140,7 @@ The parent component listens for the `(submitted)` event and receives the strong
140140
// in app.component.ts
141141
import { Component } from '@angular/core';
142142
import { JsonPipe } from '@angular/common';
143-
import { ProductFormComponent, ProductForm } from './product-form.component';
143+
import { ProductFormComponent, ProductData } from './product-form.component';
144144

145145
@Component({
146146
selector: 'app-root',
@@ -156,9 +156,9 @@ import { ProductFormComponent, ProductForm } from './product-form.component';
156156
`,
157157
})
158158
export class AppComponent {
159-
submittedData: ProductForm | null = null;
159+
submittedData: ProductData | null = null;
160160

161-
onFormSubmit(data: ProductForm) {
161+
onFormSubmit(data: ProductData) {
162162
this.submittedData = data;
163163
console.log('Product data submitted:', data);
164164
}

0 commit comments

Comments
 (0)