I have been working on creating a unique Angular 2 component known as a captcha form field, using RC5. My goal is to make this component self-sufficient so that users do not need to include @angular/forms
if they are not utilizing it.
Here is a snippet of the code:
// Component independent of '@angular/forms'
@Component({
selector: 'my-captcha',
template: `...`,
})
export class CaptchaComponent {}
// Directive depending on '@angular/forms'
@Directive({ selector: 'my-captcha' })
export class CaptchaValueAccessorDirective {}
Now, I need to export this functionality, preferably within an NgModule
:
@NgModule({
declarations: [ CaptchaComponent ],
exports: [ CaptchaComponent ],
})
export class CaptchaModule {}
@NgModule({
declarations: [ CaptchaValueAccessorDirective ],
exports: [ CaptchaValueAccessorDirective ],
imports: [ FormsModule ],
})
export class CaptchaFormsModule {}
This setup involves two modules - one with a dependency on @angular/forms
, and the other without.
Although my assumption is that most users will utilize @angular/forms
in conjunction with this component, the scenario without it is considered more of an edge case.
How can I ensure the following:
- Users who do not require
@angular/forms
do not need to load it when usingCaptchaComponent
(this is currently achieved) - Users who rely on
@angular/forms
only have to include oneNgModule
instead of bothCaptchaModule
andCaptchaFormsModule