[英]Cannot import Angular flex-layout in my feature module
我試圖在我的一個模塊中使用 Angular flex-layout,但我無法讓它工作。 當我在 app 模塊中導入 flex-layout 時,它工作得很好,但只能在 app 組件中使用。 當我在另一個模塊中導入 flex-layout 時,它根本不起作用。 我沒有收到任何錯誤,它只是不起作用。
我的代碼:
// App module
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FlexLayoutModule } from '@angular/flex-layout';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FlexLayoutModule,
AppRoutingModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
.
// AppComponent HTML - WORKS
<div fxLayout="row" fxLayoutAlign="center center">
<div fxFlex="30%">
example
</div>
</div>
.
// Other module
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FlexLayoutModule } from '@angular/flex-layout';
import { SomeRoutingModule } from './some-routing.module';
import { SomeComponent } from './pages/some-component/some-component.component';
@NgModule({
declarations: [SomeComponent],
imports: [
CommonModule,
FlexLayoutModule,
SomeRoutingModule
]
})
export class GameModule { }
.
// SomeComponent HTML - DOESN'T WORK
<div fxLayout="row" fxLayoutAlign="center center">
<div fxFlex="30%">
example
</div>
</div>
嘗試在導入下的 AppModule 中導入 GameModule。
但是,我建議您創建一個共享模塊並將 flex-layout 放在那里,因為最新的 Angular 版本支持共享模塊並且被認為是最佳實踐。 更多關於如何創建共享模塊的說明如下: https : //angular.io/guide/styleguide#shared-feature-module
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.