Issue
Trying to pass value as iframe url from local db and and im getting error message: Unsafe value used in a resource URL context. i'm trying to display an array of printers ip so i will be able to check their status via the website there is anyway to do this without iframe ? i will be more then glad to hear some advises.
I'm new to angular and every help is more then welcome thanks in advance.
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { DomSanitizer } from '@angular/platform-browser';
@Component({
selector: 'app-value',
templateUrl: './value.component.html',
styleUrls: ['./value.component.css']
})
export class ValueComponent implements OnInit {
values: any;
constructor(private http: HttpClient, private sanitizer: DomSanitizer) { }
ngOnInit() {
this.getValues();
}
getValues() {
this.http.get('http://localhost:5000/api/values/').subscribe(response => {
this.values = response;
}, error => {
console.log(error);
})
}
}
<H2>Print Manager</H2>
<div id="outerdiv">
<iframe src="http://192.168.1.6/general/status.html" id="inneriframe" scrolling="no" ></iframe>
</div>
<div *ngFor="let value of values">
<p>{{value.id}},{{value.hostName}},{{value.location}},{{value.manufacturer}},{{value.ip}}</p>
<span>Hostname: {{value.hostName}}</span>
<br>
<span>Location: {{value.location}}</span>
<br>
<span>Manufacturer: {{value.manufacturer}}</span>
<br>
<span>IP: {{value.ip}}</span>
</div>
Solution
You may use Angular DomSanitizer
from @angular/platform-browser
Refer Angular Guide for more info
import {DomSanitizationService} from '@angular/platform-browser';
@Component({
templateUrl: 'temp.html'
})
export class AppComponent {
yourUrl : '';
constructor(private sanitizer : DomSanitizationService) {
}
getSanitizedURL() {
return this.sanitizer.bypassSecurityTrustUrl(yourUrl);
}
}
HTML :
<div id="outerdiv">
<iframe src="getSanitizedURL()" id="inneriframe" scrolling="no"></iframe>
</div>
Answered By - Gauri Kesava Kumar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.