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>
但是,如果我试图通过从功能模块的组件调用来显示此微调器,它就无法工作。
您需要将此ngx-spinner移动到单独的组件中。您可以使用源组件中的next()运算符使用Subject / BehaviorSubject调用此微调器组件。
您可以使用subscribe方法监听'ngx-spinner'组件中的数据以显示/隐藏微调器。
使用要素模块和延迟加载时,还需要将NgxSpinnerModule
导入到要素模块中。
@NgModule({
imports: [
CommonModule,
NgxSpinnerModule,
...
],
})
export class FeatureModule { ... }
希望能帮助到你
使用共享模块文件分离常用模块是一种很好的做法。所以,你的
SharedModule
将是 -
@NgModule({
imports: [
CommonModule,
NgxSpinnerModule,
],
exports: [ // optional in your case
NgxSpinnerModule
],
providers: [
// ...
]
})
export class SharedModule { }
然后,
NgxSpinnerModule
的地方导入。