import {Component, OnDestroy, OnInit} from '@angular/core';
import {FormControl, FormGroup, FormGroupDirective} from '@angular/forms';
import {FormsService} from '../services/forms.service';
import {Observable} from 'rxjs/Observable';
const DEMO_OBJ = {
foo: 'foo',
bar: 'bar',
bas: 'bas'
};
const DEMO_OBJ_TWO = {
name: 'Demo Obj Two',
pizza: 'Cheese',
sammich: 'Grilled Cheese',
soda: 'Sprite',
foo: 'foo',
bar: 'bar',
bas: 'bas'
};
@Component({
selector: 'demo-component',
template: `
Reusable Inputs
Single Line Input Component
Multi-Line Input
Single With Undo
Multi Line with Undo
Dynamic Form Builder
Dynamic Master Details
`,
styles: [`
.object-builder .object-builder-input {
display: flex;
flex-direction: row;
justify-content: center;
}
`]
})
export class DemoComponent implements OnInit, OnDestroy {
public buildAnObject: {[key: string]: string}[] = [{}];
public demoObj = DEMO_OBJ;
public demoObjTwo= DEMO_OBJ_TWO;
public list: Question;
public singleText = 'This is the Demo Model';
public singleUndoText = 'This is the Demo Model';
public multiText = 'This is the Demo Model';
public multiUndoText = 'This is the Demo Model';
public singleDemoControl: FormControl = new FormControl('', []);
public singleUndoDemoControl: FormControl = new FormControl('', []);
public multiDemoControl: FormControl = new FormControl('', []);
public multiDemoUndoControl: FormControl = new FormControl('', []);
public form: FormGroup = new FormGroup({
singleDemo: this.singleDemoControl,
singleUndoDemo: this.singleUndoDemoControl,
multiDemo: this.multiDemoControl,
multiDemoUndo: this.multiDemoUndoControl
});
public dynamicForm: FormGroup = new FormGroup({});
constructor(
private forms: FormsService
){}
public ngOnInit(): void {
this.list = this.forms.buildList(this.demoObj);
console.log(this.list);
// let controls = {};
// Observable.from(this.list).forEach(question => Object.assign(controls, {[question.key]: question.control}));
// this.dynamicForm = new FormGroup(controls);
}
public ngOnDestroy(): void {}
public onChange(event): void {
console.log(event)
}
}
interface Question {
[name: string]: any
}
interface Questions {
}