Skip to content

Instantly share code, notes, and snippets.

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