2017년 6월 27일 화요일

angular 폼에서 필드를 증감할땐

angular with typescript development
좋은책이다


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
@Component({
selector: 'app',
template :`
     <form [formGroup]="formModel" (ngSubmit)="onSubmit()">
        <label>Emails</label>
        <button type="button" (click)="addEmail()">Add Email</button>
        
        이번달 :<input type="date" formControlName="calendar">
        머리카락이 남아있는 양 : <input type="range" formControlName="slider_talmo">
        <ul formArrayName="emails">
            <li *ngFor="let e of formModel.get('emails').controls; let i=index">
                <input [formControlName]="i">   
            </li>
        </ul>
        <button type="submit">Submit</button>
    </form>
    <hr>
    <label>Form Value : </label>
    <pre>{{value}}</pre>
 
    `
})
 
class AppComponent{ 
formModel : FormGroup = new FormGroup({
calendar : new FormControl(),
slider_talmo : new FormControl(),
emails : new FormArray([
new FormControl() , 
])
});
cs

댓글 없음: