简体   繁体   English

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

[英]Cannot import Angular flex-layout in my feature module

I am trying to use Angular flex-layout in one of my modules but I cannot make it work.我试图在我的一个模块中使用 Angular flex-layout,但我无法让它工作。 When I import flex-layout in app module it works just fine but only in the app component.当我在 app 模块中导入 flex-layout 时,它工作得很好,但只能在 app 组件中使用。 When I import flex-layout in another module it doesn't work at all.当我在另一个模块中导入 flex-layout 时,它根本不起作用。 I don't get any errors, it just doesn't work.我没有收到任何错误,它只是不起作用。

My code:我的代码:

// 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>

Try importing the GameModule in the AppModule under the imports.尝试在导入下的 AppModule 中导入 GameModule。

But, I would recommend you to create a shared module and place the flex-layout there beacuse latest Angular versions support shared module and is considered as best practice.但是,我建议您创建一个共享模块并将 flex-layout 放在那里,因为最新的 Angular 版本支持共享模块并且被认为是最佳实践。 More instructions on how to create a shared module is as follows: https://angular.io/guide/styleguide#shared-feature-module更多关于如何创建共享模块的说明如下: https : //angular.io/guide/styleguide#shared-feature-module

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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