` and bind
its `hidden` property to the `HeroFormComponent.submitted` property.
+makeExcerpt('src/app/hero-form.component.html (excerpt)', 'edit-div')
:marked
The main form is visible from the start because the
`submitted` property is false until we submit the form,
as this fragment from the `HeroFormComponent` shows:
+makeExcerpt('src/app/hero-form.component.ts', 'submitted')
:marked
When we click the Submit button, the `submitted` flag becomes true and the form disappears
as planned.
Now the app needs to show something else while the form is in the submitted state.
Add the following HTML below the `
` wrapper we just wrote:
+makeExcerpt('src/app/hero-form.component.html (excerpt)', 'submitted')
:marked
There's our hero again, displayed read-only with interpolation bindings.
This `
` appears only while the component is in the submitted state.
The HTML includes an _Edit_ button whose click event is bound to an expression
that clears the `submitted` flag.
When we click the _Edit_ button, this block disappears and the editable form reappears.
That's as much drama as we can muster for now.
.l-main-section
:marked
## Conclusion
The Angular form discussed in this guide takes advantage of the following
framework features to provide support for data modification, validation, and more:
- An Angular HTML form template.
- A form component class with a `@Component` decorator.
- Handling form submission by binding to the `NgForm.ngSubmit` event property.
- Template reference variables such as `#heroForm` and `#name`.
- `[(ngModel)]` syntax for two-way data binding.
- The use of `name` attributes for validation and form element change tracking.
- The reference variable’s `valid` property on input controls to check if a control is valid and show/hide error messages.
- Controlling the submit button's enabled state by binding to `NgForm` validity.
- Custom CSS classes that provide visual feedback to users about invalid controls.
Our final project folder structure should look like this:
.filetree
.file angular-forms
.children
.file src
.children
.file app
.children
.file app.component.ts
.file app.module.ts
.file hero.ts
.file hero-form.component.html
.file hero-form.component.ts
.file main.ts
.file tsconfig.json
.file index.html
.file node_modules ...
.file package.json
:marked
Here’s the code for the final version of the application:
+makeTabs(
`forms/ts/src/app/hero-form.component.ts,
forms/ts/src/app/hero-form.component.html,
forms/ts/src/app/hero.ts,
forms/ts/src/app/app.module.ts,
forms/ts/src/app/app.component.ts,
forms/ts/src/main.ts,
forms/ts/src/index.html,
forms/ts/src/forms.css`,
'final, final,,,,,',
`hero-form.component.ts,
hero-form.component.html,
hero.ts,
app.module.ts,
app.component.ts,
main.ts,
index.html,
forms.css`)