So I basically copied and pasted the code from this
http://plnkr.co/edit/0N728e9SAtXg3uBvuXKF?p=preview
To embed a youtube video.
It all works well, but now I'm trying to embed a youtube video where the "youtube video ID" is retrieved via service.
So in my controller, I do something like
APIService.getVideo($stateParams.videoId).then(function(video) {
$scope.code = video.youtube_video_id;
});
And in my template, I have
<div my-youtube code="code"></div>
But this is not working.
Basically, in the directive,
app.directive('myYoutube', function($sce) {
return {
restrict: 'EA',
scope: { code:'=' },
replace: true,
template: '<div style="height:400px;"><iframe style="overflow:hidden;height:100%;width:100%" width="100%" height="100%" src="{{url}}" frameborder="0" allowfullscreen></iframe></div>',
link: function (scope) {
scope.$watch('code', function (newVal) {
if (newVal) {
scope.url = $sce.trustAsResourceUrl("http://www.youtube.com/embed/" + newVal);
}
});
}
};
});
where there is src="{{url}}" I get "localhost/myapp/{{url}}" does not exist.
How do I get around this?