Staticinjectorerror error when using Typeahead (ngx-bootstrap)

I need to use typeahead in a component, let's call component1. The typeahead is also imported into another component (let's call it component2) which is used in within this same component1 as a modal, but are from different modules. When I import the typeahead module into component1 and keep in component2 it gives me this error

Component1.modules:

@NgModule({
    imports: [
        CommonModule,
        FullCalendarModule,
        EventoModule,
        BloquearAgendaModalModule,
        ListaBloqueiosModalModule,
        RouterModule.forChild(agendaState),
        TypeaheadModule.forRoot()
    ],
    declarations: [AgendaComponent],
    schemas: [CUSTOM_ELEMENTS_SCHEMA]
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>

Component2.modules:

@NgModule({
    imports: [CommonModule, FormsModule, ReactiveFormsModule, EnderecoModule, TypeaheadModule.forRoot()],
    declarations: [EventoComponent],
    exports: [EventoComponent],
    schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class EventoModule {}

ERROR Error: Uncaught (in promise): Error: StaticInjectorError(CoraPrevineAppModule) [TypeaheadDirective - > NgControl]: StaticInjectorError (Platform: core) [TypeaheadDirective - > NgControl]: NullInjectorError: no provider for NgControl! Error: StaticInjectorError(CoraPrevineAppModule) [TypeaheadDirective - > NgControl]: StaticInjectorError (Platform: core) [TypeaheadDirective - > NgControl]: NullInjectorError: no provider for NgControl! at NullInjector.get (core.js?09c9: 8894) at resolveToken (core.js?09c9: 9139) at tryResolveToken (core.js?09c9:9083) at StaticInjector.get (core.js?09c9: 8980) at resolveToken (core.js?09c9: 9139) at tryResolveToken (core.js?09c9:9083) at StaticInjector.get (core.js?09c9: 8980) at resolveNgModuleDep (core.js?09c9:21119) at NgModuleRef_.get (core.js?09c9:21808) at resolveNgModuleDep (core.js?09c9:21119) at resolvePromise (zone.js?d135: 831) at resolvePromise (zone.js?d135: 788) at eval (zone.js?d135: 892) at ZoneDelegate.invokeTask (zone.js?d135: 423) at Object.oninvoketask (core.js?09c9:17279) at ZoneDelegate.invokeTask (zone.js?d135: 422) at Zone.runTask (zone.js?d135:195) at drainMicroTaskQueue (zone.js?d135: 601)

Author: Daniel Freitas, 2019-11-20

1 answers

I was investigating, investigating and saw that what caused the problem was the lack of FormsModule import that is required pro typeahead to have the bind working.

 0
Author: Daniel Freitas, 2019-11-21 13:54:22