Create dynamic template with pipes?

332 Views Asked by At

Following tutorial on creating dynamic templates in Angular 2 : How can I use/create dynamic template to compile dynamic Component with Angular 2.0?

I managed to create dynamic component, but when i try to add pipe (exponentialStrength) inside template it breakes with following error:

Uncaught Error: Template parse errors:
The pipe 'exponentialStrength' could not be found 

I also tryed to add several pipes on authors plunker code preview, but it shows same error.

Is there way to implement pipe while creating dynamic template?

This is my html template:

  <div  [style]="ContentCss | safeCss">
    <input type="text" class="form-control" [disabled]="Disabled" [(ngModel)]="Entity[FieldName]" >
  </div>

and component:

import { Component, Input } from '@angular/core';
import { Observable } from "rxjs/Rx";
import { SafeHtml, SafeCss } from '../Components/sanitizeHtml.component'

@Component({
    selector: 'textbox',
    templateUrl: './textbox.component.html',
})
export class Textbox {

    @Input() public Entity: any;
    @Input() public Disabled: boolean;


}

pipe (error shows even with angular2 default pipes):

import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';

@Pipe({ name: 'safeHtml' })
export class SafeHtml implements PipeTransform {
    constructor(private sanitizer: DomSanitizer) { }

    transform(html) {
        return this.sanitizer.bypassSecurityTrustHtml(html); 
    }
}

@Pipe({ name: 'safeCss', pure:false })
export class SafeCss implements PipeTransform {
    constructor(private sanitizer: DomSanitizer) { }

    transform(style) {
        return this.sanitizer.bypassSecurityTrustStyle(style);
    }
}
0

There are 0 best solutions below