Following up on @ Günter Zöchbauer’s answer, I also modified the app.ts file.
app.ts:
//our root app component import {Component, NgModule, VERSION} from '@angular/core' import {BrowserModule} from '@angular/platform-browser' import {Child} from './child' import {FormsModule} from "@angular/forms"; @Component({ selector: 'my-app', template: ` <div> <child [value]="name" (valueChange)= "updateValue($event)"></child> <p>{{name}}</p> </div> `, }) export class App { name:string = 'MyValue'; constructor() { } updateValue(value){ this.name = value; } } @NgModule({ imports: [ BrowserModule, FormsModule ], declarations: [ App, Child ], bootstrap: [ App ] }) export class AppModule {}
Child
import {Component, Input, Output, EventEmitter} from '@angular/core' @Component({ selector: 'child', template: ` <div> <p>My custom input</p> <textarea [(ngModel)]="value" (ngModelChange)="update($event)"></textarea> </div> `, }) export class Child { @Input() value:string; @Output() valueChange:EventEmitter<string> = new EventEmitter<String>(); constructor() { } update(value) { this.valueChange.emit(value); } }
source share