Last active
April 2, 2021 14:38
-
-
Save NetanelBasal/a8d70da6e871756e0e6a9783e6564625 to your computer and use it in GitHub Desktop.
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({ | |
template: `...<button (click)="clear()">X</button>` | |
}) | |
export class InputComponent { | |
ref: InputRefDirective; | |
@ContentChild(InputRefDirective) set inputRef(ref: InputRefDirective) { | |
this.ref = ref; | |
} | |
clear() { | |
this.ref.control.patchValue(''); | |
} | |
} | |
@NgModule({ | |
declarations: [InputComponent, InputRefDirective], | |
exports: [InputComponent, InputRefDirective] | |
}) | |
export class InputModule {} |
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
@Directive({ | |
selector: '[inputRef]' | |
}) | |
export class InputRefDirective { | |
constructor(@Optional() private ngControl: NgControl) { | |
} | |
get control() { | |
return this.ngControl?.control; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment