初始化

首先初始化angular项目(确保全局安装最新@angular/cli)

  1. ng new my-project --style less --routing
  2. // 加载ng-alain(如果不是纯测试项目 为了方便开发 直接加载ng-alain)
  3. ng add ng-alain
  4. // 加载ng-zorro
  5. ng add ng-zorro-antd

增加mock

  1. // 安装yarn
  2. npm i yarn -g
  3. yarn config set registry https://registry.npm.taobao.org/
  4. yarn add @delon/mock -D
  1. "schematics": {
  2. "@schematics/angular:component": {
  3. "skipTests": true,
  4. "flat": false,
  5. "inlineStyle": true,
  6. "inlineTemplate": false,
  7. "style": "less"
  8. },
  9. "@schematics/angular:application": {
  10. "strict": true
  11. },
  12. "ng-alain:module": {
  13. "routing": true,
  14. "skipTests": true
  15. },
  16. "ng-alain:list": {
  17. "skipTests": true
  18. },
  19. "ng-alain:edit": {
  20. "skipTests": true,
  21. "modal": true
  22. },
  23. "ng-alain:view": {
  24. "skipTests": true,
  25. "modal": true
  26. },
  27. "ng-alain:curd": {
  28. "skipTests": true
  29. },
  30. "@schematics/angular:module": {
  31. "routing": true
  32. },
  33. "@schematics/angular:directive": {
  34. "skipTests": true
  35. },
  36. "@schematics/angular:service": {
  37. "skipTests": true
  38. }
  39. },

新建module

  1. // 指令
  2. ng g module routes/algorithm-preview --module routes/routes

文件:

  1. // algorithm-preview.module
  2. import { NgModule, Type } from '@angular/core';
  3. import { AlgorithmPreviewRoutingModule } from './algorithm-preview-routing.module';
  4. import { SharedModule } from '@shared';
  5. const COMPONENTS: Type<void>[] = [];
  6. @NgModule({
  7. declarations: [...COMPONENTS],
  8. imports: [SharedModule, AlgorithmPreviewRoutingModule]
  9. })
  10. export class AlgorithmPreviewModule {}
  11. // algorithm-preview-routing.module
  12. import { NgModule } from '@angular/core';
  13. import { RouterModule, Routes } from '@angular/router';
  14. const routes: Routes = [];
  15. @NgModule({
  16. imports: [RouterModule.forChild(routes)],
  17. exports: [RouterModule]
  18. })
  19. export class AlgorithmPreviewRoutingModule { }
  20. // 懒加载 routes-routing.module增加
  21. { path: 'preview', loadChildren: () => import('./algorithm-preview/algorithm-preview.module').then(m => m.AlgorithmPreviewModule) },

添加component

  1. ng g ng-alain:curd algorithm -m=algorithm-preview
  1. import { NgModule, Type } from '@angular/core';
  2. import { AlgorithmPreviewRoutingModule } from './algorithm-preview-routing.module';
  3. import { AlgorithmPreviewAlgorithmComponent } from './algorithm/algorithm.component';
  4. import { AlgorithmPreviewAlgorithmEditComponent } from './algorithm/edit/edit.component';
  5. import { AlgorithmPreviewAlgorithmViewComponent } from './algorithm/view/view.component';
  6. import { SharedModule } from '@shared';
  7. const COMPONENTS: Type<void>[] = [AlgorithmPreviewAlgorithmComponent];
  8. const COMPONENTS_NOROUNT: Type<void>[] = [AlgorithmPreviewAlgorithmEditComponent, AlgorithmPreviewAlgorithmViewComponent];
  9. @NgModule({
  10. declarations: [...COMPONENTS, ...COMPONENTS_NOROUNT],
  11. imports: [SharedModule, AlgorithmPreviewRoutingModule],
  12. entryComponents: COMPONENTS_NOROUNT
  13. })
  14. export class AlgorithmPreviewModule {}