문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판이전 판 | |||
| angular:forms [2023/09/25 06:29] – [Template Driven Forms (TDF)] taekgu | angular:forms [2025/04/15 10:05] (현재) – 바깥 편집 127.0.0.1 | ||
|---|---|---|---|
| 줄 1: | 줄 1: | ||
| + | ===== Forms ===== | ||
| + | Vital to business applications | ||
| + | Create an experience that guides the user e1fficiently and effectively through the workflow. | ||
| + | Developers | ||
| + | * Data binding | ||
| + | * Change tracking | ||
| + | * Validation | ||
| + | * Visual feedback | ||
| + | * Error messages | ||
| + | * Form submission | ||
| + | ** Angular Forms ** | ||
| + | //** Template Driven Forms **// | ||
| + | * Heavy on the component template | ||
| + | //** Reactive Forms **// | ||
| + | * Heavy on the component class | ||
| + | ==== Template Driven Forms (TDF) ==== | ||
| + | * Easy to use and similar to Angular JS Forms | ||
| + | * Two way data binding with ngModel | ||
| + | * Bulky HTML and minimal component code | ||
| + | * Automatically tracks the form and form elements state and validity | ||
| + | * Unit testing is a challenge --> 브라우저 | ||
| + | * Readablility decreases with complex forms and validations | ||
| + | * Suitable for simple scenarios | ||
| + | === Track Control State and validity === | ||
| + | <code javascript> | ||
| + | <input type=" | ||
| + | </ | ||
| + | 해쉬(# | ||
| + | 적용되는 class는 < | ||
| + | |||
| + | ^State ^Class if true ^Class if false^ | ||
| + | |The control has been visited.|ng-touched|ng-untouched| | ||
| + | |The control' | ||
| + | |The control' | ||
| + | |||
| + | === ngModel properties === | ||
| + | ^Class | ||
| + | |ng-untouched | ||
| + | |ng-touched | ||
| + | |ng-pristine | ||
| + | |ng-dirty | ||
| + | |ng-valid | ||
| + | |ng-invalid | ||
| + | |||
| + | <code javascript> | ||
| + | <div class=" | ||
| + | < | ||
| + | <input type=" | ||
| + | </ | ||
| + | {{ name.className }} | ||
| + | {{ name.touched }} | ||
| + | </ | ||
| + | # | ||
| + | |||
| + | === class property적용 === | ||
| + | <code javascript> | ||
| + | <input type=" | ||
| + | </ | ||
| + | **[class.is-invalid]=" | ||