gpt4 book ai didi

angular - 库中的组件不适用于 ngIf/ngFor

转载 作者:行者123 更新时间:2023-12-04 01:39:13 26 4
gpt4 key购买 nike

我有一个应用程序正在尝试升级到 angular 5 和 library-tize。
我设置了 ng-packagr 以便构建和捆绑 lib,这没问题,直到我尝试使用带有 ngIf 或 ngFor 的组件之一,这给了我错误

HeaderComponent.html:13 ERROR Error: StaticInjectorError[ViewContainerRef]: 
StaticInjectorError[ViewContainerRef]:
NullInjectorError: No provider for ViewContainerRef!
at _NullInjector.get (core.js:993)

在运行时。我环顾四周并尝试了一些不同的东西,但似乎没有任何解决方法......

这是该库的相关模块代码。
@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 {}

这是报告错误的 HTML。
          <a class="hidden-xs" trigger-resize="" (click)="toggleCollapsedSideabar()" *ngIf="!isCollapsedText()">
<i class="material-icons">menu</i>
</a>

最佳答案

您应该将 BrowserModule 添加到您的导入数组中。

@NgModule({
imports: [
BrowserModule, <----- add this
CommonModule,
FormsModule,
RouterModule,

更多信息 here .

关于angular - 库中的组件不适用于 ngIf/ngFor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48103492/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com