На основе учебника Дэвида Иста (https://gist.github.com/davideast/0b7efc93e0ba9aaa446e). Я пытаюсь сделать так, чтобы Angular2 работал на примере очень крошечных форм.
В основном я хотел бы, чтобы каждый раз, когда входное значение изменялось, какое-то событие запускалось и перехватывалось моим наблюдателем. Но по какой-то странной причине мой код не работает...
версии lib: typescript 1.5.0-бета, Angular-2.0.0-28
Вот код машинописного текста:
/// <reference path="../../typings/angular2/angular2.d.ts" />
/// <reference path="../../typings/angular2/angular2_addons.d.ts" />
import {Component, View, bootstrap, Form, EventEmitter} from 'angular2/angular2';
import {FormBuilder, Validators, formDirectives, ControlGroup} from 'angular2/forms';
import {Inject} from 'angular2/di';
@Component({
selector: 'mycmp',
appInjector: [FormBuilder]
})
@View({
template: '<form [ng-form-model]="myForm"><input type="text" ng-control="myText">{{myForm.controls.myText.value}}</form>',
directives: [formDirectives],
})
export class MyCmp {
myForm:ControlGroup;
constructor(@Inject(FormBuilder) builder:FormBuilder) {
this.myForm = builder.group({
myText: ["someDefaultVal...", Validators.required]
});
this.myForm.controls.myText.valueChanges.subscribe(function (value) {
console.log("changed value=" + value);
}.bind(this));
}
}
bootstrap(MyCmp);
К сожалению, я получаю TypeError: this.myForm.controls.myText.valueChanges.subscribe is not a function