Perhaps in the second version you are missing Event Emitter for two-way binding.
You need to add abcChange
Please see this demo here - it works great:
import {Component, NgModule, VERSION, Input, Output, EventEmitter} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {FormsModule} from '@angular/forms';
@Component({
selector: 'tpc-ts',
template: `
<input [(ngModel)]="model">
<div>{{model}}</div>
`
})
export class TsComponent {
_model: string;
@Output()
valueChange: EventEmitter<string> = new EventEmitter<string>();
@Input('value')
set model(value: string) {
this._model = value;
this.valueChange.emit(this._model);
}
get model() {
return this._model;
}
}
@Component({
selector: 'my-app',
template: `
<div>
<h2>Hello {{name}}</h2>
<tpc-ts [(value)]="name"></tpc-ts>
</div>
`,
})
export class App {
name:string;
constructor() {
this.name = `Angular! v${VERSION.full}`
}
}
@NgModule({
imports: [ BrowserModule, FormsModule ],
declarations: [ App, TsComponent ],
bootstrap: [ App ]
})
export class AppModule {}
Online demo: http://plnkr.co/edit/y9GVu7?p=preview
source
share