Created
May 15, 2017 19:42
-
-
Save squadwuschel/79bee6f4e037896fca17c27bc7d2870f to your computer and use it in GitHub Desktop.
two-way-databinding Angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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