diff --git a/adev/src/content/examples/attribute-directives/src/app/app.component.html b/adev/src/content/examples/attribute-directives/src/app/app.component.html index c8eb07c6a6b..0c6c52f0416 100644 --- a/adev/src/content/examples/attribute-directives/src/app/app.component.html +++ b/adev/src/content/examples/attribute-directives/src/app/app.component.html @@ -17,13 +17,13 @@

-
+

Mouse over the following lines to see fixed highlights

Highlighted in yellow

Highlighted in orange

-
+

ngNonBindable

diff --git a/adev/src/content/examples/dynamic-form/src/app/app.component.ts b/adev/src/content/examples/dynamic-form/src/app/app.component.ts index 35487ed06ee..245074c77c3 100644 --- a/adev/src/content/examples/dynamic-form/src/app/app.component.ts +++ b/adev/src/content/examples/dynamic-form/src/app/app.component.ts @@ -13,7 +13,7 @@ import {Observable} from 'rxjs'; template: `

Job Application for Heroes

- +
`, providers: [QuestionService], diff --git a/adev/src/content/examples/dynamic-form/src/app/dynamic-form.component.html b/adev/src/content/examples/dynamic-form/src/app/dynamic-form.component.html index b17fc4eb625..d5121c2cd23 100644 --- a/adev/src/content/examples/dynamic-form/src/app/dynamic-form.component.html +++ b/adev/src/content/examples/dynamic-form/src/app/dynamic-form.component.html @@ -3,7 +3,7 @@
@for (question of questions(); track question) {
- +
} diff --git a/adev/src/content/examples/dynamic-form/src/app/dynamic-form.component.ts b/adev/src/content/examples/dynamic-form/src/app/dynamic-form.component.ts index 83f06fdc401..af90014900b 100644 --- a/adev/src/content/examples/dynamic-form/src/app/dynamic-form.component.ts +++ b/adev/src/content/examples/dynamic-form/src/app/dynamic-form.component.ts @@ -1,6 +1,5 @@ // #docregion -import {Component, input, Input, OnInit} from '@angular/core'; -import {CommonModule} from '@angular/common'; +import {Component, inject, input} from '@angular/core'; import {FormGroup, ReactiveFormsModule} from '@angular/forms'; import {DynamicFormQuestionComponent} from './dynamic-form-question.component'; @@ -14,17 +13,13 @@ import {QuestionControlService} from './question-control.service'; providers: [QuestionControlService], imports: [DynamicFormQuestionComponent, ReactiveFormsModule], }) -export class DynamicFormComponent implements OnInit { +export class DynamicFormComponent { + qcs = inject(QuestionControlService); + questions = input[] | null>([]); - form!: FormGroup; + form: FormGroup = this.qcs.toFormGroup(this.questions() as QuestionBase[]); payLoad = ''; - constructor(private qcs: QuestionControlService) {} - - ngOnInit() { - this.form = this.qcs.toFormGroup(this.questions() as QuestionBase[]); - } - onSubmit() { this.payLoad = JSON.stringify(this.form.getRawValue()); } diff --git a/adev/src/content/examples/form-validation/src/app/app.component.ts b/adev/src/content/examples/form-validation/src/app/app.component.ts index 848aa748d95..ec60c3caa01 100644 --- a/adev/src/content/examples/form-validation/src/app/app.component.ts +++ b/adev/src/content/examples/form-validation/src/app/app.component.ts @@ -1,9 +1,9 @@ // #docregion import {Component} from '@angular/core'; import {ActorFormReactiveComponent} from './reactive/actor-form-reactive.component'; -import {ActorFormComponent} from '../../../forms/src/app/actor-form/actor-form.component'; import {ReactiveFormsModule} from '@angular/forms'; import {FormsModule} from '@angular/forms'; +import {ActorFormTemplateComponent} from './template/actor-form-template.component'; @Component({ selector: 'app-root', @@ -11,6 +11,11 @@ import {FormsModule} from '@angular/forms';
`, - imports: [ActorFormComponent, ActorFormReactiveComponent, FormsModule, ReactiveFormsModule], + imports: [ + ActorFormReactiveComponent, + FormsModule, + ReactiveFormsModule, + ActorFormTemplateComponent, + ], }) export class AppComponent {} diff --git a/adev/src/content/examples/form-validation/src/app/reactive/actor-form-reactive.component.html b/adev/src/content/examples/form-validation/src/app/reactive/actor-form-reactive.component.html index abfdfece05f..4cac0fe4302 100644 --- a/adev/src/content/examples/form-validation/src/app/reactive/actor-form-reactive.component.html +++ b/adev/src/content/examples/form-validation/src/app/reactive/actor-form-reactive.component.html @@ -1,4 +1,4 @@ - +

Reactive Form

@@ -7,58 +7,59 @@
-
+
+ formControlName="name" required> - @if(name.invalid && (name.dirty || name.touched)) { + @if (name.invalid && (name.dirty || name.touched)) {
- @if(name.hasError('required')) { + + @if (name.hasError('required')) {
Name is required.
} - @if(name.hasError('minlength')) { + @if (name.hasError('minlength')) {
Name must be at least 4 characters long.
} - @if(name.hasError('forbiddenName')) { + @if (name.hasError('forbiddenName')) {
Name cannot be Bob.
}
} -
-
+ formControlName="role"> - @if(role.pending) { -
- Validating... + @if (role.pending) { +
Validating...
+ } + @if (role.invalid) { +
+ @if (role.hasError('uniqueRole')) { +
+ Role is already taken. +
+ }
} - @if(role.invalid) { -
- @if(role.hasError('uniqueRole')) { - Role is already taken. -
-
- @if(actorForm.hasError('unambiguousRole') && (actorForm.touched || actorForm.dirty)) { + @if (actorForm.hasError('unambiguousRole') && (actorForm.touched || actorForm.dirty)) {
Name cannot match role or audiences will be confused.
@@ -69,16 +70,16 @@
- @if(skill.invalid && skill.touched) { + @if (skill.invalid && skill.touched) {
- @if(skill.hasError('required')) { - Skill is required. + @if (skill.hasError('required')) { +
Skill is required.
}
} @@ -87,13 +88,15 @@

Complete the form to enable the Submit button.

+ [disabled]="actorForm.invalid">Submit + + (click)="formDir.resetForm({})">Reset +
- @if(formDir.submitted) { + @if (formDir.submitted) {