首页 > 解决方案 > 如何将节点导入语句添加到具有角度示意图的文件中?

问题描述

我想要一个自定义原理图,它将在我的应用程序中创建一个页面。为此,我想使用现有的核心原理图创建一个路由模块,然后在该模块中创建一个组件来显示我的页面内容,最后将所有内容连接在一起。让我难过的是“将所有东西连接在一起”。我找不到关于“正确”方法的明确指导。我是不是该:

a) 直接修改“模块”和“组件”原理图创建的现有文件?(我不知道该怎么做)

b)使用模板以某种方式将修改合并到文件中?(我也不知道该怎么做)

以下是到目前为止我的页面示意图的 index.ts 文件。我不知道该怎么做,最后由“TODO”评论。

请帮忙!

import {
  externalSchematic,
  Rule,
  SchematicContext,
  Tree,
  chain,
} from '@angular-devkit/schematics';

export function page(options: any): Rule {
  const name = options.name;

  return chain([
    // create module for this page
    externalSchematic('@schematics/angular', 'module', {
      name: `pages/${name}`,
      routing: true
    }),

    // create simple component to display in this page
    externalSchematic('@schematics/angular', 'component', {
      name: `pages/${name}/${name}`,
      routing: true
    }),

    // add component to routing module
    (tree: Tree, _context: SchematicContext) => {
      // TODO 1: import new component into routing module
      // e.g. import { MyPageComponent } from "./my-page/my-page.component";

      // TODO 2: add component to routes
      // const routes: Routes = [{ path: '', pathMatch: 'full', component: MyPageComponent }];
      return tree;
    },
  ]);
}

标签: node.jsangularangular-schematics

解决方案


推荐阅读