UNPKG

angular-formio

Version:

Form.io Angular JSON Form Renderer ========================== This library serves as a Dynamic JSON Powered Form rendering library for [Angular](https://angular.io). This works by providing a JSON schema to a ```<formio>``` Angular component, where that f

35 lines (30 loc) 1.03 kB
import { Component, ElementRef, ViewChild, AfterViewInit } from '@angular/core'; import Prism from 'prismjs'; @Component({ template: require('./builder.html') }) export class BuilderComponent implements AfterViewInit { @ViewChild('json') jsonElement?: ElementRef; @ViewChild('code') codeElement?: ElementRef; public form: Object = { components: [] }; onChange(event) { this.jsonElement.nativeElement.innerHTML = ''; this.jsonElement.nativeElement.appendChild(document.createTextNode(JSON.stringify(event.form, null, 4))); } ngAfterViewInit() { let formattedCode = Prism.highlight(`import { Component, ElementRef, ViewChild } from '@angular/core'; @Component({ template: require('./builder.html') }) export class BuilderComponent { @ViewChild('json') jsonElement?: ElementRef; public form: Object = {components: []}; onChange(event) { console.log(event.form); } }`, Prism.languages.javascript, 'javascript'); this.codeElement.nativeElement.innerHTML = formattedCode; } }