我正尝试在我的一个模块中使用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>发布于 2020-04-02 20:10:27
尝试在导入下的AppModule中导入GameModule。
但是,我建议你创建一个共享模块,并将flex-layout放在那里,因为最新的Angular版本支持共享模块,并被认为是最佳实践。有关如何创建共享模块的更多说明如下:https://angular.io/guide/styleguide#shared-feature-module
https://stackoverflow.com/questions/60991032
复制相似问题