innerHTML ignores my angular directives
See original GitHub issueI’m submitting a … (check one with “x”)
[ ] bug report => check the FAQ and search github for a similar issue or PR before submitting
[ ] support request => check the FAQ and search github for a similar issue before submitting
[x] feature request
Current behavior
I have the below translation token (includes HTML tag with an angular directive)
"MSG":"You may <a routerLink='/login'> Sign in </a> again"
and my component HTML is
<div [innerHTML]="'MSG' | translate"></div>
The final translation strips of the routerLink
directive
Expected/desired behavior
The final translation should have routerLink
directive
ng2-translate version: 6.0.1
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:19
Top Results From Across the Web
Angular 2: How can I apply directives to sanitized html/innerhtml
I would like to create a directive that is applied to the innerhtml, but while the html is displayed, it is not compiled...
Read more >How To Use the innerHTML Property Binding in Angular
Angular 2+ supports an [innerHTML] property binding that will render HTML. If you were to otherwise use interpolation, it would be treated ...
Read more >Reapplying an Angular Directive on DOM Changes - Medium
We want this behavior to be added by an Angular Directive. But a Directive will not be re-executed unless the element it is...
Read more >Using Angular innerHtml to display user-generated content ...
The issue is that DomSanitizer is stripping too much out of my HTML, and there's no way to configure its rules. In my...
Read more >Template syntax - Angular
To eliminate the risk of script injection attacks, Angular does not support the <script> element in templates. Angular ignores the <script> tag and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
import { AfterViewInit, Directive, ElementRef, Input, OnDestroy, Renderer2 } from ‘@angular/core’; import { TranslateService } from ‘translate-core’; import { Router } from ‘@angular/router’;
@Directive({ selector: ‘[appTranslate]’ }) export class TranslateDirective implements AfterViewInit, OnDestroy { @Input() appTranslate: string; listenClickFunc: Function;
constructor(private element: ElementRef, private translate: TranslateService, private router: Router, private renderer: Renderer2) {}
ngAfterViewInit() { this.translate.get(this.appTranslate).subscribe((translateText: string) => { this.element.nativeElement.innerHTML = translateText; // this.cdRef.detectChanges();
}
ngOnDestroy() { this.listenClickFunc(); }
}
So, to be clear, does this mean that an existing, working angularJS app that features custom directives inserted by ng-bind-html, then compiled with $compile, cannot be upgraded to angular 2+? And that there isn’t even a workaround? Given that for back-compatibilty reasons the inserted HTML content cannot be changed, is the app now stuck with the end-of-life angularJS forever? I’m sorry, but that seems to be a major hole in angular, which I would hope to see addressed in a release sooner rather than later.