I was trying to concatenate https://www.youtube.com/embed/
with $ctrl.video.id.videoId
so what I did is:
<iframe class="embed-responsive-item" src="{{'https://www.youtube.com/embed/' + $ctrl.video.id.videoId}}" allowFullScreen></iframe>
But this gives us an error:
Error: [$sce:insecurl] Blocked loading resource from url not allowed by $sceDelegate policy. URL: https://www.youtube.com/embed/OPxeCiy0RdY
http://errors.angularjs.org/1.6.9/$sce/insecurl?p0=https%3A%2F%2Fwww.youtube.com%2Fembed%2FOPxeCiy0RdY
http://errors.angularjs.org/1.6.9/$interpolate/interr?p0=%7B%7B'https%3A%2F%2Fwww.youtube.com%2Fembed%2F'%20%2B%20%24ctrl.video.id.videoId%7D%7D&p1=Error%3A%20%5B%24sce%3Ainsecurl%5D%20Blocked%20loading%20resource%20from%20url%20not%20allowed%20by%20%24sceDelegate%20policy.%20%20URL%3A%20https%3A%2F%2Fwww.youtube.com%2Fembed%2FOPxeCiy0RdY%0Ahttp%3A%2F%2Ferrors.angularjs.org%2F1.6.9%2F%24sce%2Finsecurl%3Fp0%3Dhttps%253A%252F%252Fwww.youtube.com%252Fembed%252FOPxeCiy0RdY
at angular.js:116
at Function.$interpolateMinErr.interr (angular.js:12922)
at parseStringifyInterceptor (angular.js:13258)
at Array.regularInterceptedExpression (angular.js:16777)
at interpolationFn (angular.js:13230)
at Object.attrInterpolatePreLinkFn (angular.js:10510)
at angular.js:1383
at invokeLinkFn (angular.js:10619)
at nodeLinkFn (angular.js:9985)
at compositeLinkFn (angular.js:9248)
(anonymous) @ angular.js:14800
Search on some threads and found some possible solution in stack overflow so edited the main module and put a filter function in there for trustUrl:
angular.module('video-player', [])
.config(function($sceDelegateProvider) {
$sceDelegateProvider.resourceUrlWhitelist([
'self',
'https://www.youtube.com/**'
]);
})
.filter('trustUrl', function ($sce) {
return function(url) {
return $sce.trustAsResourceUrl(url);
}
});
But still no luck. I don't know what's causing this error.