Ngx-Spinner无法在功能模块中使用

问题描述 投票:1回答:3

Ngx-Spinner当我在主模块里面调用它时工作正常,即app-module

我在整页上使用line spinner所以我在app-component.html中定义它

<ngx-spinner bdColor="rgba(51, 51, 51, 0.47)" size="medium" color="#fff" type="line-spin-clockwise-fade"></ngx-spinner>

但是,如果我试图通过从功能模块的组件调用来显示此微调器,它就无法工作。

angular spinner
3个回答
1
投票

您需要将此ngx-spinner移动到单独的组件中。您可以使用源组件中的next()运算符使用Subject / BehaviorSubject调用此微调器组件。

您可以使用subscribe方法监听'ngx-spinner'组件中的数据以显示/隐藏微调器。


0
投票

使用要素模块和延迟加载时,还需要将NgxSpinnerModule导入到要素模块中。

@NgModule({
    imports: [
        CommonModule,
        NgxSpinnerModule,
        ...
    ],
})
export class FeatureModule { ... }

希望能帮助到你


0
投票

使用共享模块文件分离常用模块是一种很好的做法。所以,你的SharedModule将是 -

@NgModule({
    imports: [
        CommonModule,
        NgxSpinnerModule,
    ],
    exports: [    // optional in your case
        NgxSpinnerModule
    ],
    providers: [
        // ...
    ]
})
export class SharedModule { }

然后,

  • 只需在需要NgxSpinnerModule的地方导入。
  • 您可以根据需要添加许多外部模块。
© www.soinside.com 2019 - 2024. All rights reserved.