代码之家  ›  专栏  ›  技术社区  ›  Serhii

有棱角的模块结构

  •  0
  • Serhii  · 技术社区  · 9 年前

    angular-cli

    我生成了一个模块:

    $  ng generate module myTestModule
    installing module
      create src/app/my-test-module/my-test-module.module.ts
    
    $  ng generate module myTestModule2
    installing module
      create src/app/my-test-module2/my-test-module2.module.ts
    

    1. 我有常用的文件描述主要模块 app.module.ts .我可以注册模块 my-test-module.module.ts app.module.ts 和 my-test-module2.module.ts 在

    I在许多模块上的红分裂应用程序提供了更好的性能。但我对此感到困惑。如果我使用一些数据加载功能来 URI1 module1 加载数据,我导航到 URI2 模块1 module2 模块1 正在再次保持活动状态,并再次加载相同的数据!我错过了什么吗?

    3. angular

    2 回复  |  直到 9 年前
        1
  •  1
  •   Mauricio De La Quintana    9 年前

    您好,谈谈您的优点:

    • https://angular.io/guide/styleguide#application-structure-and-angular-modules
    • https://angular.io/guide/ngmodule#lazy-loading-modules-with-the-router 这将使您基于路由器导入所需的内容。例如,主屏幕只需要加载一个组件,并且应该尽可能快。
    • 智能导入,当导入库时,我们通常会出错,我们不需要整个导入,一个例子是。

      import { Observable } from 'rxjs/Observable';
      import * from "rxjs";
      

      在这个例子中,我们只使用可观察的,不需要导入整个库,因为这将使我们的包更大。将我们的代码拆分成模块将允许像本例一样进行智能导入。

       import { MdToolbarModule} from '@angular/material';
       // import { MaterialModule } from '@angular/material';
       imports: [
         // MaterialModule.forRoot(),
         MdToolbarModule,
       ], 
      

      我们本可以导入整个库,但由于这是一个简单的组件,我们只需要一个短模块。

        2
  •  1
  •   A. Tim    9 年前

    module1 和 module2 Service 然后放进去 core.module ,每个应用程序只需导入该模块一次。有棱角的io的文档页面名为 Style Guide ,请阅读,它有一些非常重要和有用的注释,关于你的项目结构(特别是概念 core shared

    如果 模块1 和 执行不同的请求,您希望缓存该请求(即,当导航回时,不要第二次执行) )-您必须手动“缓存”该数据(只需将结果保存到 service ).

    根据我的理解,当您具有多模块结构时,您可以: -do公司 Lazy Load

    推荐文章