Bit confused about how to use Forms(template or modal driven froms) in the angular2 beta.
currently i am using modal driven forms but getting some error here is my form.html:
<form [ngFormModel]="demo">
<input type="text" [ngFormControl]="demo.controls['name']">
<input type="text" [ngFormControl]="demo.controls['batch']">
<div>
<input type="radio" [ngFormControl]="demo.controls['radio']" name="status" value="true"> Active
<input type="radio" [ngFormControl]="demo.controls['radio']" name="status" value="false">Inactive
</div>
<div>
<input type="checkbox" [ngFormControl]="demo.controls['checkbox']" name="one" value="one"> one
<input type="checkbox" [ngFormControl]="demo.controls['checkbox']" name="two" value="two">two
</div>
<select [ngFormControl]="demo.controls['select']">
<option value="one">Oone</option>
<option value="two">two</option>
<option value="three">three</option>
<option value="four">four</option>
</select>
<button type="button" class="btn btn-primary btn-lg" data-dismiss="modal" (click)="demoSubmit(demo.value)">Done</button>
</form>
and form.ts file is here:
import {Component, View} from 'angular2/core';
import {FORM_DIRECTIVES, CORE_DIRECTIVES, FormBuilder, Control, ControlGroup} from 'angular2/common';
import {ROUTER_DIRECTIVES} from 'angular2/router';
@Component({
selectro: 'Form',
templateUrl: 'src/components/form/form.html',
directives: [CORE_DIRECTIVES, FORM_DIRECTIVES],
})
export class FormDemo{
demo:ControlGroup;
constructor(fb:FormBuilder){
console.log("Form Called");
this.demo= fb.group({
name: ["pardeep"],
batch: [],
checkbox: [],
radio: [],
select: []
})
}
demoSubmit (){
console.log(JSON.stringify(this.demo.value));
}
}
so, my questions is:
- which form is best template or modal driven and why ?
- when to use ngControl and when to use ngModal ?
PS:- in this example i am unable to get the values of radio button and check-box selected am i doing something wrong, in this example i am modal driven form From here?
any good reference or example is welcome. thanks.