import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `<h1>Hello {{name}}</h1>
<iframe src="http://hssa:1021/Home?testRequestId=+[testRequestId]+" allowfullscreen></iframe>`,
})
export class AppComponent {
name = 'Angular';
testRequestId = '3224';
}
I have my .ts
file as mentioned above. How do I pass testRequestId
to html?
try this:
Online demo
Safe Pipe
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer} from '@angular/platform-browser';
@Pipe({ name: 'safe' })
export class SafePipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {}
transform(url: string) {
return this.sanitizer.bypassSecurityTrustResourceUrl(url);
}
}
AppComponent
import {Component} from '@angular/core';
@Component({
selector: 'app-root',
template: `
<iframe [src]="'https://www.youtube.com/embed/' + testRequestId | safe" width="560" height="315" allowfullscreen></iframe>
`
})
export class AppComponent {
testRequestId: string = 'uelHwf8o7_U';
}
because Angular not trust any source, it'll sanitize the content, then we need bypass it.
Learn more about this topic: https://angular.io/docs/ts/latest/guide/security.html
Template syntax
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With