In angular 1 we could do one time binding in this way: {{ ::myFunction() }}
.
In angular 2 this is throwing:
EXCEPTION: Template parse er
I found solution for one time binding in angular 2 here: https://github.com/angular/angular/issues/14033
I created this directive:
import { Directive, TemplateRef, ViewContainerRef, NgZone } from "@angular/core";
@Directive({
selector: '[oneTime]',
})
export class OneTimeDirective {
constructor(template: TemplateRef, container: ViewContainerRef, zone: NgZone) {
zone.runOutsideAngular(() => {
const view = container.createEmbeddedView(template);
setTimeout(() => view.detach());
})
}
}
And used it:
For example: