在 app.module 上导入模式表单

Import schema-form on the app.module

我正在尝试在 angular 项目中使用 angular-schema-form,但无法将其导入我的 app.module.ts。这是我的配置:

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { schemaForm } from 'angular-schema-form';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    schemaForm
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

然而,当我尝试 运行 ng serve 时,它正确地符合,但浏览器显示错误,指出 schemaForm 未定义:Uncaught Error: Unexpected value 'undefined' imported by the module 'AppModule'

我已经使用 npm-install 正确安装了依赖项,但我无法生成单个表单。阅读它说的官方文档:

load the schemaForm module in your module definition

它显示了如何使用以下方式导入它的示例:angular.module('myModule', ['schemaForm'])。问题是我没有使用 angular.module 启动我的模块,而是使用上面代码中显示的 @NgModule 引导方法。该项目是使用 angular CLI 命令 ng new project

从头开始​​创建的

有人可以指导我如何导入和使用 angular-schema-form 的正确方向吗?谢谢。

这个包是angularjs包。它不是为 angular 构建的。请找到 os 为 angular 构建的模式形式的其他包。检查 this link for your reference

实际回答如何使用 Angular Schema FormAngular 的问题仍然只适用于 AngularJS 你需要使用 ngUpgrade 库。

ASF库将升级支持Angular,但这是一个耗时的过程,除非有更多人协助迁移项目,否则可能需要很长时间。