angular2 forms observable / event

By : Sigma6
Source: Stackoverflow.com
Question!

Based on David East tutorial (https://gist.github.com/davideast/0b7efc93e0ba9aaa446e) I'm trying to get Angular2 observable working on very tiny forms example.

Basically I would like that each time an input value changes some event is fired and caught by my observer. But for some weird reason my code doesn't work...

lib versions: typescript 1.5.0-beta, Angular-2.0.0-28

Here is the Typescript code:

/// <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);

Unfortunately I'm getting TypeError: this.myForm.controls.myText.valueChanges.subscribe is not a function

By : Sigma6


Answers

If you just want to fire some function every time the value of your input changes, then you can do something like this:

By : kakaja


I could not find any subscriber function, so I used the observer:

this.myForm.valueChanges.observer({next: (value) =


This video can help you solving your question :)
By: admin