docs: use `json` pipe in Forms guide instead of a temporary diagnostic field (#42364)
Closes #37283. PR Close #42364
This commit is contained in:
parent
44027c4e0e
commit
e917d57dbb
|
@ -1,6 +1,7 @@
|
||||||
// #docregion
|
// #docregion
|
||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { BrowserModule } from '@angular/platform-browser';
|
import { BrowserModule } from '@angular/platform-browser';
|
||||||
|
import { CommonModule } from '@angular/common';
|
||||||
import { FormsModule } from '@angular/forms';
|
import { FormsModule } from '@angular/forms';
|
||||||
|
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
@ -9,6 +10,7 @@ import { HeroFormComponent } from './hero-form/hero-form.component';
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
|
CommonModule,
|
||||||
FormsModule
|
FormsModule
|
||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
|
|
|
@ -147,7 +147,7 @@
|
||||||
<form #heroForm="ngForm">
|
<form #heroForm="ngForm">
|
||||||
<!-- #enddocregion template-variable-->
|
<!-- #enddocregion template-variable-->
|
||||||
<!-- #docregion ngModel-2-->
|
<!-- #docregion ngModel-2-->
|
||||||
{{diagnostic}}
|
{{ model | json }}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="name">Name</label>
|
<label for="name">Name</label>
|
||||||
<input type="text" class="form-control" id="name"
|
<input type="text" class="form-control" id="name"
|
||||||
|
|
|
@ -23,8 +23,6 @@ export class HeroFormComponent {
|
||||||
// #enddocregion submitted
|
// #enddocregion submitted
|
||||||
|
|
||||||
// #enddocregion final
|
// #enddocregion final
|
||||||
// TODO: Remove this when we're done
|
|
||||||
get diagnostic() { return JSON.stringify(this.model); }
|
|
||||||
// #enddocregion v1
|
// #enddocregion v1
|
||||||
|
|
||||||
// #docregion final, new-hero
|
// #docregion final, new-hero
|
||||||
|
|
|
@ -220,7 +220,7 @@ Any unique value will do, but using a descriptive name is helpful.
|
||||||
|
|
||||||
2. You can now remove the diagnostic messages that show interpolated values.
|
2. You can now remove the diagnostic messages that show interpolated values.
|
||||||
|
|
||||||
3. To confirm that two-way data binding works for the entire hero model, add a new binding at the top to the component's `diagnostic` property.
|
3. To confirm that two-way data binding works for the entire hero model, add a new text binding with the [`json` pipe](api/common/JsonPipe) (which would serialize the data to a string) at the top to the component's template.
|
||||||
|
|
||||||
After these revisions, the form template should look like the following:
|
After these revisions, the form template should look like the following:
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ If you run the app now and change every hero model property, the form might disp
|
||||||
|
|
||||||
The diagnostic near the top of the form confirms that all of your changes are reflected in the model.
|
The diagnostic near the top of the form confirms that all of your changes are reflected in the model.
|
||||||
|
|
||||||
4. When you have observed the effects, you can delete the `{{diagnostic}}` binding.
|
4. When you have observed the effects, you can delete the `{{ model | json }}` text binding.
|
||||||
|
|
||||||
## Track control states
|
## Track control states
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue