I am new to Angular 2 without AngularJS experience and working on a tutorial involving the setting of an iframe src attribute:
<iframe width="100%" height="300" src="{{video.url}}"></iframe>
This throws an exception:
Error: unsafe value used in a resource URL context
at DomSanitizationServiceImpl.sanitize...
I have already tried using bindings with [src]
with no success. I am probably missing something and I have had a hard time finding a solution to this.
Update
For RC.6^ version use DomSanitizer
Plunker
And a good option is using pure pipe for that:
remember to add your new
SafePipe
to thedeclarations
array of the AppModule. (as seen on documentation)html
Plunker
If you use
embed
tag this might be interesting for you:Old version RC.5
You can leverage
DomSanitizationService
like this:And then bind to
url
in your template:Don't forget to add the following imports:
Plunker sample
I had been struggling for 4 hours. the problem was in img tag. When you use square bracket to 'src' ex: [src]. you can not use this angular expression {{}}. you just give directly from an object example below. if you give angular expression {{}}. you will get interpolation error.
first i used ngFor to iterate the countries
second you put this in the img tag. this is it.
This works me to Angular 5.2.0
sarasa.Component.ts
sarasa.Component.html
thats all folks!!!
Congratulation ! ¨^^ I have an easy & efficient solution for you, yes!
Great ;)
This one works for me.