Skip to content

Instantly share code, notes, and snippets.

@ahkohd
Last active June 29, 2019 22:43
Show Gist options
  • Save ahkohd/dcfa16eee08ee7907ddeb804d1588fc1 to your computer and use it in GitHub Desktop.
Save ahkohd/dcfa16eee08ee7907ddeb804d1588fc1 to your computer and use it in GitHub Desktop.
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