-
Notifications
You must be signed in to change notification settings - Fork 1
Angular Forms
-
Form is something you can simply submit to the server. With Angular, you're creating a single page application, so there is no submitting to the server, instead you will need to handle the form through Angular and if you then want to submit something to the server, you will need to reach out via Angular's HTTP service
-
Angular ships with some powerful tools that helps in handling/working with form
- allow you to get the values the user entered
- it will also allow you to check if a form is valid
- it will allow you to conditionally change the way the form is displayed
- put some red borders around invalid controls
-
Angular offers two approaches to deal with form -
-
Template Driven Approach - you simply set up your form in the template (in HTML code) and Angular will automatically infer the structure of your form i.e. which controls your forms has, which inputs and makes it easy for you to get started quickly.
-
Angular infers such forms, create such a JavaScript object for us as it does when using the template driven approach.
-
It is dependent on
FormsModule
, so import this inapp.module
fileimport { FormsModule } from '@angular/forms'; ... imports: [ FormsModule ],
- Reactive Approach - you actually define the structure of the form in Typescript code, you also set up the HTML code and then you manually connect it. This gives you greater control over form, you can fine tune every little piece about your form.