Skip to content

Instantly share code, notes, and snippets.

@squadwuschel
Created May 15, 2017 19:42
Show Gist options
  • Save squadwuschel/79bee6f4e037896fca17c27bc7d2870f to your computer and use it in GitHub Desktop.
Save squadwuschel/79bee6f4e037896fca17c27bc7d2870f to your computer and use it in GitHub Desktop.
two-way-databinding Angular
import { Component, Input, Output, EventEmitter } from '@angular/core';
@Component({
selector: 'my-child',
template: `<p>V1 Childvalue Name: "{{name}}"<br/><input [(ngModel)]="name" (keyup)="onNameChanged()"> <br/><br/>
<p>V2 Childvalue Age: "{{age}}"<br/><input [(ngModel)]="age" (keyup)="onAgeChanged()"> <br/></p>`
})
export class ChildComponent {
@Input() name : string;
@Output() nameChange = new EventEmitter<string>();
@Input() age : string;
@Output() ageChanged = new EventEmitter<string>();
public onNameChanged() {
this.nameChange.emit(this.name);
}
public onAgeChanged() {
this.ageChanged.emit(this.age);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment