Last active
August 6, 2022 14:01
-
-
Save aniketmuruskar/12429a2fd2bd08154febd6dd865b6c5b to your computer and use it in GitHub Desktop.
Page builder service to resolve component based componentType
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Type } from '@angular/core'; | |
export class AddComponent { | |
constructor( | |
public component: Type<any>, | |
public config: any, | |
public data: string | |
) {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { AddComponent } from '../add.component'; | |
import { CheckboxComponent } from '../app-dynamic-component/checkbox/checkbox.component'; | |
import { DropdownComponent } from '../app-dynamic-component/dropdown/dropdown.component'; | |
import { LabelComponent } from '../app-dynamic-component/label/label.component'; | |
import { RadioComponent } from '../app-dynamic-component/radio/radio.component'; | |
import { TextareaComponent } from '../app-dynamic-component/textarea/textarea.component'; | |
import { TextboxComponent } from '../app-dynamic-component/textbox/textbox.component'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class PageBuilderService { | |
constructor() { } | |
buildPage(pageElements: any): any { | |
let pageDetails: Array<any> = []; | |
pageElements.forEach((page: any) => { | |
pageDetails.push(this.getPageElement(page)); | |
}) | |
return pageDetails; | |
} | |
private getPageElement(page: any): AddComponent | void { | |
if (page.componentType === 'label') { | |
return new AddComponent(LabelComponent, page, page.data); | |
} else if (page.componentType === 'textbox') { | |
return new AddComponent(TextboxComponent, page, page.value); | |
} else if (page.componentType === 'dropdown') { | |
return new AddComponent(DropdownComponent, page, page.value); | |
} else if (page.componentType === 'checkbox') { | |
return new AddComponent(CheckboxComponent, page, page.value); | |
} else if (page.componentType === 'radio') { | |
return new AddComponent(RadioComponent, page, page.value); | |
} else if (page.componentType === 'textarea') { | |
return new AddComponent(TextareaComponent, page, page.value); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment