Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. /// <reference path="../../typings/angular2/angular2.d.ts" />
  2. /// <reference path="../../typings/angular2/angular2_addons.d.ts" />
  3. import {Component, View, bootstrap, Form, EventEmitter} from 'angular2/angular2';
  4. import {FormBuilder, Validators, formDirectives, ControlGroup} from 'angular2/forms';
  5. import {Inject} from 'angular2/di';
  6.  
  7. @Component({
  8. selector: 'mycmp',
  9. appInjector: [FormBuilder]
  10. })
  11. @View({
  12. template: '<form [ng-form-model]="myForm"><input type="text" ng-control="myText">{{myForm.controls.myText.value}}</form>',
  13. directives: [formDirectives],
  14. })
  15. export class MyCmp {
  16. myForm:ControlGroup;
  17. constructor(@Inject(FormBuilder) builder:FormBuilder) {
  18. this.myForm = builder.group({
  19. myText: ["someDefaultVal...", Validators.required]
  20. });
  21.  
  22. this.myForm.controls.myText.valueChanges.subscribe(function (value) {
  23. console.log("changed value=" + value);
  24. }.bind(this));
  25. }
  26. }
  27.  
  28. bootstrap(MyCmp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement