`包装下方,添加下列 HTML 语句:
+makeExcerpt('src/app/hero-form.component.html (excerpt)', 'submitted')
:marked
There's the hero again, displayed read-only with interpolation bindings.
This `
` appears only while the component is in the submitted state.
英雄又出现了,它通过插值表达式绑定显示为只读内容。
这一小段 HTML 只在组件处于已提交状态时才会显示。
The HTML includes an *Edit* button whose click event is bound to an expression
that clears the `submitted` flag.
这段HTML包含一个 “Edit(编辑)”按钮,将 click 事件绑定到表达式,用于清除`submitted`标志。
When you click the *Edit* button, this block disappears and the editable form reappears.
当点*Edit*按钮时,这个只读块消失了,可编辑的表单重新出现了。
.l-main-section
:marked
## Conclusion
## 结论
The Angular form discussed in this page takes advantage of the following
framework features to provide support for data modification, validation, and more:
本章讨论的 Angular 表单技术利用了下列框架特性来支持数据修改、验证和更多操作:
* An Angular HTML form template.
Angular HTML 表单模板。
* A form component class with a `@Component` decorator.
带有`@Component`装饰器的表单组件类。
* Handling form submission by binding to the `NgForm.ngSubmit` event property.
通过绑定到`NgForm.ngSubmit`事件属性来处理表单提交。
* Template-reference variables such as `#heroForm` and `#name`.
模板引用变量,例如`#heroForm`和`#name`。
* `[(ngModel)]` syntax for two-way data binding.
`[(ngModel)]`语法用来实现双向数据绑定。
* The use of `name` attributes for validation and form-element change tracking.
`name`属性的用途是有效性验证和对表单元素的变更进行追踪。
* The reference variable’s `valid` property on input controls to check if a control is valid and show/hide error messages.
指向 input 控件的引用变量上的`valid`属性,可用于检查控件是否有效、是否显示/隐藏错误信息。
* Controlling the *Submit* button's enabled state by binding to `NgForm` validity.
通过绑定到`NgForm`的有效性状态,控制*Submit*按钮的禁用状态。
* Custom CSS classes that provide visual feedback to users about invalid controls.
定制 CSS 类来给用户提供无效控件的视觉反馈。
The 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`)