[Angular2 Form] Create and Submit an Angular 2 Form using ngForm
2016-09-27 18:36
381 查看
Forms in Angular 2 are essentially wrappers around
Make sure you need to add 'name' prop to both form and input fields. This helps to structure the form model.
ngModel is reuqire by ngForm, so you need to use ngModel on input field even you don't assign anything to it.
inputs that group the input values together into an object and also check that all the inputs are valid. Angular 2 ‘s
ngFormallows you to get a reference to that object and validity and use them to display information about the form or use the
ngSubmitevent to save information from the form.
Make sure you need to add 'name' prop to both form and input fields. This helps to structure the form model.
<form action="" name="myForm" #formRef="ngForm" (ngSubmit)="onSubmit(formRef.value)"> Firstname: <input type="text" name="firstName"ngModel required> <button [disabled]="!formRef.valid">Submit</button> </form> <pre> form value: {{formRef.value | json}} form valid: {{formRef.valid | json}} </pre>
ngModel is reuqire by ngForm, so you need to use ngModel on input field even you don't assign anything to it.
相关文章推荐
- 转载:How to create an automation project using MFC and a type library
- How do I create an IIS application and application pool using InnoSetup script
- Create an Asp.Net Web Forms Application using Bootstrap and Web API
- [Angular] Create custom validators for formControl and formGroup
- [AngularJS] Using an AngularJS directive to hide the keyboard on submit
- 53 Which statement about using RMAN stored scripts is true? A. To create and execute an RMA
- HOWTO: Create and submit your first Linux kernel patch using GIT
- Create and submit your first Linux kernel patch using GIT
- HOWTO: Create and submit your first Linux kernel patch using GIT
- HOWTO: Create and submit your first Linux kernel patch using GIT
- [Angular2 Form] Create custom form component using Control Value Accessor
- An Extensive Examination of LINQ: Querying and Searching XML Documents Using LINQ to XML
- Matrix and linear algebra in F#, Part IV: profile your program, find the bottleneck and speed it up: using matrix multiplication as an example[z]
- Using Qt to build an Omi App for iOS (and Android)
- Send an image from the iPhone using ASIHTTP and UIImagePicker
- Images; How to create an HTTP handler to dynamically resize images and change quality.
- Applications using Launch Screen Files and targetting iOS 7.1 and earlier need to also include a Launch Image in an Asset Catalog.
- How to submit an InfoPath form to a Windows SharePoint Services document library
- Using Qt to build an Omi App for iOS (and Android)
- How to get Full Rom Dump / Stock ROM of MT6572 MediaTek Smartphones using SPFT and MTK Droid Root an