Last active
June 29, 2019 22:43
-
-
Save ahkohd/dcfa16eee08ee7907ddeb804d1588fc1 to your computer and use it in GitHub Desktop.
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 { | |
Pipe, | |
PipeTransform | |
} from '@angular/core'; | |
@Pipe({ | |
name: 'PipeForm' | |
}) | |
export class FormPipe implements PipeTransform { | |
// transforms the pipe input and returns a string following this format `[[<input/>]]` | |
transform(elem: string, type: string, options ? : object): string { | |
// declare output container.. | |
let out: string; | |
// switch between the type if element we want to create | |
switch (elem) { | |
case 'input': | |
// case input tag, | |
out = `[[<input type="${type}"`; | |
// loop through the options parameter and format it into the out variable like HTML attributes. | |
Object.entries(options).forEach((value: string[]) => { | |
out += ` ${value[0]}="${value[1]}"`; | |
}); | |
break; | |
} | |
// append the final, ending string. | |
out += '/>]]'; | |
// we done here ;-) | |
return out; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment