繁体   English   中英

无法在我的功能模块中导入 Angular flex-layout

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM