Last active
November 16, 2019 12:22
-
-
Save kevinchisholm/7a551554ec77950e13a1e6aa0a5d5475 to your computer and use it in GitHub Desktop.
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, Output, EventEmitter } from '@angular/core'; | |
@Component({ | |
selector: 'child1', | |
templateUrl: 'src/child1/child1.html', | |
}) | |
export class Child1Component { | |
@Output() nameEvent = new EventEmitter<string>(); | |
@Output() phoneEvent = new EventEmitter<string>(); | |
userName: string = ''; | |
userPhone: string = ''; | |
onNameChange () { | |
this.nameEvent.emit(this.userName); | |
} | |
onPhoneChange () { | |
this.phoneEvent.emit(this.userPhone); | |
} | |
} |
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
<input | |
type="text" | |
(keyup)="onNameChange()" | |
[(ngModel)]="userName" | |
placeholder="Enter user name here"> | |
<input | |
type="text" | |
(keyup)="onPhoneChange()" | |
[(ngModel)]="userPhone" | |
placeholder="Enter user phone number here"> |
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, Output, EventEmitter } from '@angular/core'; | |
@Component({ | |
selector: 'child2', | |
templateUrl: 'src/child2/child2.html' | |
}) | |
export class Child2Component { | |
@Output() nameEvent = new EventEmitter<string>(); | |
@Output() phoneEvent = new EventEmitter<string>(); | |
userName: string = ''; | |
userPhone: string = ''; | |
onNameChange () { | |
this.nameEvent.emit(this.userName); | |
} | |
onPhoneChange () { | |
this.phoneEvent.emit(this.userPhone); | |
} | |
} |
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
<input | |
type="text" | |
(keyup)="onNameChange()" | |
[(ngModel)]="userName" | |
placeholder="Enter user name here"> | |
<input | |
type="text" | |
(keyup)="onPhoneChange()" | |
[(ngModel)]="userPhone" | |
placeholder="Enter user phone number here"> |
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 } from '@angular/core'; | |
@Component({ | |
selector: 'parent', | |
templateUrl: 'src/parent/parent.html' | |
}) | |
export class ParentComponent { | |
public userName = ''; | |
public userPhone = ''; | |
nameEventHander($event: any) { | |
this.userName = $event; | |
} | |
phoneEventHander($event: any) { | |
this.userPhone = $event; | |
} | |
} |
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
<strong>Name: </strong> {{userName}} | |
<strong>Phone: </strong> {{userPhone}} | |
<child1 | |
(nameEvent)="nameEventHander($event)" | |
(phoneEvent)="phoneEventHander($event)"></child1> | |
<child2 | |
(nameEvent)="nameEventHander($event)" | |
(phoneEvent)="phoneEventHander($event)"></child2> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment