Last active
May 9, 2019 08:30
-
-
Save armanozak/024c2458bc14b4bf6e2658f4d3b991d8 to your computer and use it in GitHub Desktop.
Angular Context - Two-way Data-binding (#1) #blog
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
@Component({ | |
selector: 'my-app', | |
template: ` | |
<context-provider provide="rate pre onRating"> | |
<two-way></two-way> | |
</context-provider> | |
{{ rate }} | |
`, | |
}) | |
export class AppComponent { | |
rate = 1; | |
get pre(): number { | |
return this.rate; | |
} | |
onRating = (value: number) => { | |
this.rate = value; | |
} | |
} |
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
@Component({ | |
selector: 'two-way', | |
template: ` | |
<rating | |
contextConsumer | |
[contextMap]="{rate: 'value', pre: 'preValue', onRating: 'onChange'}" | |
></rating> | |
`, | |
}) | |
export class TwoWayComponent {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment