1

I tried to put HTML content in a tag. The div tag displays a page. But script tag doesn't work. Looks this code...

getRequestToAssignPage (param: string) : any {
    return this.$http.get(param)
        .map((res: Response) => {
            this.status = res;
            return res.text()
        })
        .toPromise()
        .then(response => this.response = response)
        .catch(error => this.status = error);

}

That's method make a request with get a new page, and convert it to text. Then i put text to the div tag. Like this.

<div [innerHTML]="response"></div>

it works! page is display, but script tags doesn't work, and it displays how the text. After page was load, below content belong the text

jQuery(document).ready(function () { jQuery('#filter-form').yiiActiveForm([], []); jQuery('#id-vendors-list').yiiGridView({"filterUrl":"/vendors/vendor/index","filterSelector":"#w0-filters input, #w0-filters select"}); });

How can i fix that?

1 Answer 1

1

You probably have a problem with the safe HTML.

Try implementing this pipe:

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

@Pipe({
  name: 'safe'
})
@Injectable()
export class SafePipe {
   constructor(private sanitizer: DomSanitizer) {}
   transform(url) {
   return this.sanitizer.bypassSecurityTrustResourceUrl(url);
}
}

And then:

<div [innerHTML]="response | safe"></div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.