我正在按照https://github.com/formio/angular-formio/wiki/Form-Builder的说明进行操作,即使没有客户端错误,我也没有看到在我的页面上呈现任何表单生成器。
这是我看到的:https ://imgur.com/a/9CL7oRF 由于某种原因,表单生成器被呈现为 0x0。
我的代码:
问卷-builder.component.ts
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
@Component({
selector: 'questionnaire-builder',
templateUrl: './questionnaire-builder.component.html',
styleUrls: ['./questionnaire-builder.component.css']
})
export class QuestionnaireBuilderComponent{
@ViewChild('json', {static: true}) jsonElement?: ElementRef;
public form: Object = {components: []};
onChange(event) {
this.jsonElement.nativeElement.innerHTML = '';
this.jsonElement.nativeElement.appendChild(
document.createTextNode(JSON.stringify(event.form, null, 4)));
}
}
问卷-builder.component.html
<p>Is form-builder working?</p>
<form-builder [form]="{
components: []
}"></form-builder>
<form-builder [form]="form" (change)="onChange($event)"></form-builder>
<div class="well jsonviewer">
<pre id="json"><code class="language-json" #json></code></pre>
</div>
问卷.module.ts
...
import {FormioModule} from 'angular-formio';
import {MatFormioModule} from 'angular-material-formio';
import {QuestionnaireBuilderComponent} from './questionnaire-builder/questionnaire-builder.component';
@NgModule({
declarations: [
QuestionnaireBuilderComponent,
],
exports: [],
entryComponents: [
QuestionnaireBuilderComponent,
],
imports: [
...
MatFormioModule,
FormioModule,
],
})
export class QuestionnaireModule {
}