Last active
May 9, 2019 08:30
-
-
Save armanozak/1d38efa2531b516f72c41e244d2e2d6e to your computer and use it in GitHub Desktop.
Angular Context - Two-way Data-binding (#2) #blog
This file contains hidden or 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
@Component({ | |
selector: 'my-app', | |
template: ` | |
<context-provider provide="rate onRating"> | |
<two-way></two-way> | |
</context-provider> | |
{{ rate }} | |
`, | |
}) | |
export class AppComponent { | |
rate = 1; | |
onRating = (value: number) => { | |
this.rate = value; | |
} | |
} |
This file contains hidden or 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
@Component({ | |
selector: 'two-way', | |
template: ` | |
<context-consumer consume="rate onRating"></context-consumer> | |
<rating | |
[ngModel]="rate" | |
(ngModelChange)="onRating($event)" | |
></rating> | |
`, | |
}) | |
export class TwoWayComponent { | |
rate: number; | |
onRating: (rate: number) => void; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment