+ *
Submit the form to see the data object Angular builds
+ *
NgForm demo
+ *
+ *
{{data}}
+ *
+ * `,
+ * directives: [CORE_DIRECTIVES, FORM_DIRECTIVES]
+ * })
+ * export class App {
+ * constructor() {}
+ *
+ * data: string;
+ *
+ * onSubmit(data) {
+ * this.data = JSON.stringify(data, null, 2);
+ * }
+ * }
+ * ```
+ *
+ * @experimental
+ */
+@Directive({
+ selector: 'form:not([ngNoForm]):not([ngFormModel]),ngForm,[ngForm]',
+ providers: [formDirectiveProvider],
+ host: {
+ '(submit)': 'onSubmit()',
+ },
+ outputs: ['ngSubmit'],
+ exportAs: 'ngForm'
+})
+export class NgForm extends ControlContainer implements Form {
+ private _submitted: boolean = false;
+
+ form: ControlGroup;
+ ngSubmit = new EventEmitter();
+
+ constructor(@Optional() @Self() @Inject(NG_VALIDATORS) validators: any[],
+ @Optional() @Self() @Inject(NG_ASYNC_VALIDATORS) asyncValidators: any[]) {
+ super();
+ this.form = new ControlGroup({}, null, composeValidators(validators),
+ composeAsyncValidators(asyncValidators));
+ }
+
+ get submitted(): boolean { return this._submitted; }
+
+ get formDirective(): Form { return this; }
+
+ get control(): ControlGroup { return this.form; }
+
+ get path(): string[] { return []; }
+
+ get controls(): {[key: string]: AbstractControl} { return this.form.controls; }
+
+ addControl(dir: NgControl): void {
+ PromiseWrapper.scheduleMicrotask(() => {
+ var container = this._findContainer(dir.path);
+ var ctrl = new Control();
+ setUpControl(ctrl, dir);
+ container.registerControl(dir.name, ctrl);
+ ctrl.updateValueAndValidity({emitEvent: false});
+ });
+ }
+
+ getControl(dir: NgControl): Control { return