在"dotnet new angular"项目中使用angular-tree-component?

Wil*_*sch 22 tree dotnet-cli angular

当尝试将angular-tree-component集成到使用"dotnet new angular"创建的项目中时,我始终遇到异常"void(0)不是函数." 树永远不会出现,或者它会短暂出现,但随后错误发生并消失.我想这是由于包版本问题,因为组件自己的演示工作正常.但我不知道哪个包,或者解决方法可能是什么.

我已经将此作为一个问题交叉发布到角度树组件论坛,并且还作为公共回购进行了各种尝试.

有任何想法吗?

don*_*j87 1

我刚刚自己测试过,它可以在 chrome 版本 73.0.3683.86 上运行。我使用了 Visual Studio 代码,但你可以使用任何你想要的。

  1. 创建一个文件夹并使用 VS Code 打开它
  2. 打开终端并执行dotnew new angular命令 - 这将创建一个 .net core 应用程序
  3. 执行ng new tree-test命令 - 它创建一个名为 tree-test 的 Angular 应用程序。出现提示时选择yes, 然后选择scss格式
  4. 执行cd tree-test- 将工作文件夹更改为新创建的角度应用程序
  5. 执行npm install --save angular-tree-component- 这会将您的组件安装到应用程序中
  6. 打开tree-test>src>styles.scss文件并在其中添加一行:@import '~angular-tree-component/dist/angular-tree-component.css';- 这将使您的树样式起作用
  7. 打开app.module.ts文件并添加import { TreeModule } from 'angular-tree-component';到标题并设置导入,如下所示:imports: [..., TreeModule.forRoot()]
  8. 打开app.component.html文件并将所有内容替换为<tree-root [nodes]="nodes" [options]="options"></tree-root>
  9. 打开app.component.ts所有AppComponent课程内容并将其替换为以下内容:
nodes = [
    {
      id: 1,
      name: 'root1',
      children: [
        { id: 2, name: 'child1' },
        { id: 3, name: 'child2' }
      ]
    },
    {
      id: 4,
      name: 'root2',
      children: [
        { id: 5, name: 'child2.1' },
        {
          id: 6,
          name: 'child2.2',
          children: [
            { id: 7, name: 'subsub' }
          ]
        }
      ]
    }
  ];
  options = {};
Run Code Online (Sandbox Code Playgroud)
  1. 运行ng serve命令,等待其完成并在http://localhost:4200. 你会在那里看到一棵漂亮的树。