Last active
May 9, 2019 08:30
-
-
Save armanozak/597bbfc47b75fd7dcd839ca2880e1454 to your computer and use it in GitHub Desktop.
Angular Context - Two-way Data-binding (#4) #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: ` | |
<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], | |
}); | |
} | |
} |
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: ` | |
<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