我有现有的应用程序,现在我想添加延迟加载。
我的应用程序结构如下
lastElement DWORD ?
现在,我在每个组件中添加app
core
| |-shared.module.ts
| |-core.module.ts
|
|--home
| |
| |-home.component.ts
| |-home.component.html
| |-home.component.css
|
|--users
| |
| |-users.component.ts
| |-users.component.html
| |-users.component.css
|
app.component.ts
app.component.html
app.component.css
app.module.ts
app-routing.module.ts
和home.module.ts and home-routing.module.ts
还从我的users.module.ts and home-routing.module.ts
中将所有导入内容移至app.module
和shared.module
现在,在我的core.module
中,像这样
app.module
在import { BrowserModule } from "@angular/platform-browser";
import { NgModule, ModuleWithProviders } from "@angular/core";
import { CoreModule } from "../../../core/core-module";
import { SharedModule } from "../../../core/shared.app.module.dependency";
// views
import { AppComponent } from "./app.component";
import { AppRoutingModule } from "./app-routing.module";
import { RouterModule } from "@angular/router";
import { HomeModule } from "./home/home.module";
import { UsersModule } from "./users/users.module";
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
RouterModule,
AppRoutingModule,
SharedModule,
CoreModule,
HomeModule,
UsersModule
providers: [],
bootstrap: [AppComponent]
})
export class AdminModule {}
中设置
core.module
在import { NgModule, ModuleWithProviders, APP_INITIALIZER } from
"@angular/core";
import { CommonModule } from "@angular/common";
import { HttpClientModule, HttpClient, HTTP_INTERCEPTORS } from
"@angular/common/http";
import { ReactiveFormsModule, FormsModule } from "@angular/forms";
import { BrowserAnimationsModule } from "@angular/platform-
browser/animations";
import { BrowserModule } from "@angular/platform-browser";
@NgModule({
imports: [CommonModule, BrowserModule, BrowserAnimationsModule,
HttpClientModule, FormsModule, ReactiveFormsModule, KeycloakAngularModule],
declarations: [],
exports: [BrowserModule]
})
export class CoreModule {}
中,我将需要的所有内容导入到我的应用程序中,例如角材料(我将其设置为导入和导出),还包括CommonModule,FormsModule,ReactiveFormsModule等...
现在,在我的“ home.module”中,导入共享的模块和组件
shared.module
在共享模块中,我导入了所有重要的依赖关系。在此之前,一切工作正常
import { NgModule } from "@angular/core";
import { CommonModule } from "@angular/common";
import { HomeComponent } from "./home.component";
import { SharedModule } from "projects/core/shared.app.module.dependency";
import { RouterModule } from "@angular/router";
import { HomeRoutingModule } from "./home-routing.module";
@NgModule({
declarations: [HomeComponent],
imports: [CommonModule, RouterModule, HomeRoutingModule, SharedModule]
})
export class HomeModule {}