It seems like the directive is replacing the template, then running the trust resource function, which updates the source, then it is updating the template again and getting stuck in a loop. But this is the recommended method?? The html:
<player videos='[{"type":"mp4","src":"http://vjs.zencdn.net/v/oceans.mp4","poster":"http://www.videojs.com/img/poster.jpg","captions":"http://www.videojs.com/vtt/captions.vtt"},{"type":"webm","src":"http://vjs.zencdn.net/v/oceans.webm"}]' />
And this is the javascript:
module.directive('player', ['$sce', function ($sce) {
'use strict';
return {
restrict: 'E',
scope: {
videos: '='
},
link: function (scope, element, attrs) {
scope.trustSrc = function(src) {
return $sce.trustAsResourceUrl(src);
}
},
template: '<video preload="none" poster="{{ trustSrc(videos[0].poster) }}">' +
'<source ng-repeat="item in videos" ng-src="{{ trustSrc(item.src) }}" type="video/{{ item.type }}" />' +
'<track kind="captions" ng-src="{{ trustSrc(videos[0].captions) }}" srclang="en" label="English" />' +
'</video>'
};
}]);
And here is a working fiddle: