/* Copyright (c) 2019 AT&T Intellectual Property. #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #
# you may not use this file except in compliance with the License. #
# You may obtain a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
##############################################################################*/
import { Component, OnInit, Input, Output, EventEmitter, ViewChild, NgModuleRef, Injector, Compiler, NgModule, ViewContainerRef } from '@angular/core';
import { FormGroup, FormControl, ReactiveFormsModule } from '@angular/forms';
import { MatSnackBar } from '@angular/material';
import { AlertSnackbarComponent } from '../alert-snackbar/alert-snackbar.component';
@Component({
selector: 'app-form-generator',
templateUrl: './form-generator.component.html',
styleUrls: ['./form-generator.component.scss']
})
export class FormGeneratorComponent implements OnInit {
public test = {
text1: "Hello please enter text1",
text2: "Hello please enter text2",
one: {
text1: "lol"
},
siteSpecific: {
port: "1234",
host: "google.com"
},
list: ["Enter", "some", "values"],
list2: [{"test": "hello"}, {"test2": "hello2"}]
}
public isSaved = false;
public arrayCheck;
@Input() public JSONData : any;
@Input() public taskId: any;
@ViewChild('test', { read: ViewContainerRef }) public containerDiv;
@Output() public childEvent = new EventEmitter();
form = new FormGroup({
});
//public textAreaTemplate = ""
const tmpCmp = Component({template: textAreaTemplate})(class {
});
const tmpModule = NgModule({imports:[ReactiveFormsModule], declarations: [tmpCmp]})(class {
});
//this.containerDiv.element.nativeElement.appendChild(document.createElement("label")).innerHTML = key.trim();
this.compiler.compileModuleAndAllComponentsAsync(tmpModule)
.then((factories) => {
const f = factories.componentFactories[0];
const cmpRef = this.containerDiv.createComponent(f);
cmpRef.instance.form = this.form;
})
}
else{
const textAreaTemplate = '