I have an app I am trying to upgrade to angular 5 and library-tize. I setup ng-packagr so the lib is built and bundled, this is no problem until I try to use one of the components with ngIf or ngFor which give me the error
HeaderComponent.html:13 ERROR Error: StaticInjectorError[ViewContainerRef]:
StaticInjectorError[ViewContainerRef]:
NullInjectorError: No provider for ViewContainerRef!
at _NullInjector.get (core.js:993)
at runtime. I have looked around and tried some different things but nothing seems to fix it...
Here is relevant module code for the library.
@NgModule({
imports: [
CommonModule,
FormsModule,
RouterModule,
/* Bootstrap Imports */
AccordionModule,
AlertModule,
ButtonsModule,
CarouselModule,
CollapseModule,
BsDropdownModule,
ModalModule,
PaginationModule,
ProgressbarModule,
RatingModule,
TabsModule,
TimepickerModule,
TooltipModule,
TypeaheadModule,
DatepickerModule,
ServicesModule,
],
declarations: [
LayoutComponent,
HeaderComponent,
FooterComponent,
OffsidebarComponent,
SidebarComponent,
UserblockComponent,
OverlayComponent,
BusyIndicatorComponent
],
exports: [
LayoutComponent
],
providers: [
UserblockService
]
})
export class ComponentsModule {}
Here is the HTML where the error is reported.
<a class="hidden-xs" trigger-resize="" (click)="toggleCollapsedSideabar()" *ngIf="!isCollapsedText()">
<i class="material-icons">menu</i>
</a>
You should add BrowserModule to your imports array.
@NgModule({
imports: [
BrowserModule, <----- add this
CommonModule,
FormsModule,
RouterModule,
More info here.
Removing the dependencies from library's package.json
before adding the library to the main app was the fix for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With