【发布时间】:2018-02-26 07:38:54
【问题描述】:
我正在使用最新版本的 Angular 和 Angular Material。我已经实现了延迟加载功能模块,无需材料设计即可正常工作。
我需要在我的视图中使用以下三个材料组件/模块 -
MatSidenav 模块, MatIcon模块, MatListModule
只有在实现延迟加载时,我才会收到 模板解析错误。请在附件中找到错误的屏幕截图。
我创建了如下的材料共享模块并导入功能模块。 素材共享模块代码。
import { NgModule, ModuleWithProviders } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
// material designs
import {
MatSidenavModule,
MatIconModule,
MatListModule,
MatIconRegistry
} from '@angular/material';
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
MatSidenavModule,
MatIconModule,
MatListModule
],
exports: [
BrowserModule,
BrowserAnimationsModule,
MatSidenavModule,
MatIconModule,
MatListModule
]
})
export class MaterialSharedModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: MaterialSharedModule,
providers: [MatIconRegistry]
};
}
}
我正在导入我的功能模块“LandingPage.module.ts”,如下所示 -
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
/* // material designs
import {
MatSidenavModule,
MatIconModule,
MatListModule
} from '@angular/material'; */
import { AppSharedModule } from '../shared.module';
import { SharedModule } from '../shared/shared.module';
import { LandingRoutingModule } from './landing-routings.module';
import { **MaterialSharedModule** } from '../material.shared.module';
@NgModule({
imports: [
CommonModule,
**MaterialSharedModule**,
SharedModule,
LandingRoutingModule
],
declarations: [
]
})
export class LandingPageModule { }
下面是 LandingFeature 模块路由 -
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './home/home.component';
const routes: Routes = [
{ path: '', pathMatch: 'prefix', redirectTo: 'dashboard' },
{ path: 'dashboard', component: HomeComponent, data: { title: 'Dashboard', path : 'dashboard' } },
/* {
path: 'tenantManagement',
loadChildren: 'app/tenant/tenant-routings.module#TenantRoutingModule'
},
{
path: 'application',
loadChildren: 'app/application-registraion/application-routings.module#ApplicationRoutingModule',
data : {title: 'application', path: 'application'}
} */
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
declarations: [
HomeComponent
]
})
export class LandingRoutingModule { }
【问题讨论】:
标签: angular angular-material angular-material2 angular5