javascript - Using $sce in Angular -


i'm having trouble getting head around showing iframes in angular app. users allowed enter youtube url , app convert straight video.

of course, angular won't allow directly have explicitly "trust" contents use show iframe:

$sce.trustasresourceurl(url_of_video) 

however, how back? want able send url back-end in sanitized form it's no longer original url string.

update:

experimenting , came code:

angular.foreach($scope.task.items, function(item) {   item.data = $sce.gettrustedresourceurl(item.data); //this gets rejected $sce   item.data2 = $sce.gettrustedresourceurl(item.data); //this accepted , i'm free post url }); 

i've noticed can create new name/value pair in array , assign original url if try assign item.data trusted form of sanitized data rejects it! hmmmmm! why this?

any ideas?

update 2 decided create 2 versions of data, 1 front end (which "trusted" $sce) , 1 back. appears have solved issue moment.

take @ this answers (which contains links yet more answers , resources).

you should understand implications of trusting content entered user , $sce there for.

if want allow youtube urls, might better idea "white-list" urls (instead of trusting url entered user).
(don't forget sce not there make app bullet-proof, tool make safer , audit easier/more reliably.)


that said, here how configure angular's sce allow urls www.youtube.com:

.config(function ($scedelegateprovider) {     $scedelegateprovider.resourceurlwhitelist([         'self',                    // trust resources same origin         '*://www.youtube.com/**'   // trust resources `www.youtube.com`     ]); }); 

see, also, short demo other answer (that want).


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -