Skip to content

Instantly share code, notes, and snippets.

@armanozak
Last active May 9, 2019 08:30
Show Gist options
  • Save armanozak/024c2458bc14b4bf6e2658f4d3b991d8 to your computer and use it in GitHub Desktop.
Save armanozak/024c2458bc14b4bf6e2658f4d3b991d8 to your computer and use it in GitHub Desktop.
Angular Context - Two-way Data-binding (#1) #blog
@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;
}
}
@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