Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit d48afe2

Browse files
reset refactor
1 parent 373d0a7 commit d48afe2

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

public/docs/_examples/reactive-forms/ts/app/hero-detail-7.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ export class HeroDetailComponent7 implements OnChanges {
3636

3737
// #docregion onchanges
3838
ngOnChanges() {
39-
this.heroForm.reset();
40-
this.heroForm.patchValue({
39+
// #docregion reset-refactor
40+
this.heroForm.reset({
4141
name: this.hero.name
4242
});
43+
// #enddocregion reset-refactor
4344
this.setAddresses(this.hero.addresses);
4445
}
4546
// #enddocregion onchanges

public/docs/ts/latest/guide/reactive-forms.jade

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,9 @@ a#data-model-form-model
494494
+makeExample('reactive-forms/ts/app/hero-detail-5.component.ts', 'imports')(format=".")
495495

496496
:marked
497-
# Ward, `hero-detail-5.component.ts` is where `@Input() hero: Hero;`
498-
# shows up for the first time, but I don't understand it or know where
499-
# I should mention it. It seems like this is the general area, but we don't demonstrate it.
497+
## Ward, `hero-detail-5.component.ts` is where `@Input() hero: Hero;`
498+
## shows up for the first time, but I don't understand it or know where
499+
## I should mention it. It seems like this is the general area, but we don't demonstrate it.
500500

501501
.l-main-section
502502
a#set-data
@@ -585,6 +585,16 @@ a#set-data
585585

586586
+makeExample('reactive-forms/ts/app/hero-detail-6.component.ts', 'set-value-on-changes','app/hero-detail.component.ts (excerpt)')(format=".")
587587

588+
:marked
589+
You could, however, reset the value of the *formControls* in the `reset()`
590+
method by refactoring.
591+
## Ward, are the benefits that now you can dispense with `setValue` (so less code
592+
## and you don't have to set everything)? In `hero-detail-7.component.ts`, we also have
593+
## `this.setAddresses(this.hero.addresses);` in `ngOnChanges`.
594+
## Do I need to include it and talk about it?
595+
596+
+makeExample('reactive-forms/ts/app/hero-detail-7.component.ts', 'reset-refactor','app/hero-detail.component.ts (excerpt)')(format=".")
597+
588598
a#hero-list
589599
:marked
590600
### Create the _HeroListComponent_ and _HeroService_
@@ -834,7 +844,7 @@ figure.image-display
834844
Instead, it must prepare `saveHero` whose values derive from a combination of original hero values (the `hero.id`)
835845
and deep copies of the potentially-changed form model values.
836846

837-
# Ward, stop lecturing :D
847+
## Ward, stop lecturing :D
838848

839849
+makeExample('reactive-forms/ts/app/hero-detail.component.ts', 'prepare-save-hero','app/hero-detail.component.ts (prepareSaveHero)')(format=".")
840850

0 commit comments

Comments
 (0)