Skip to content

Instantly share code, notes, and snippets.

@armanozak
Last active May 9, 2019 08:30
Show Gist options
  • Save armanozak/597bbfc47b75fd7dcd839ca2880e1454 to your computer and use it in GitHub Desktop.
Save armanozak/597bbfc47b75fd7dcd839ca2880e1454 to your computer and use it in GitHub Desktop.
Angular Context - Two-way Data-binding (#4) #blog
@Component({
selector: 'my-app',
template: `
<form [formGroup]="form">
<context-provider provide="rate">
<two-way></two-way>
</context-provider>
</form>
{{ rate }}
`,
})
export class AppComponent {
form: FormGroup;
get rate(): AbstractControl {
return this.form.controls.rating;
}
constructor(private fb: FormBuilder) {
this.fb.group({
rating: [1],
});
}
}
@Component({
selector: 'two-way',
template: `
<ng-template contextDisposer="rate" let-control="rate">
<rating *ngIf="control" [formControl]="control"></rating>
</ng-template>
`,
})
export class TwoWayComponent {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment