1
How to pass a $scope.video_url
for a javascript function in my view?
I have a service that returns the id of a video, and in my view I have a javascript infunction that starts the youtube player according to this id, but how do I pass this id to the function?
created a service, but no video appeared in my view.
myApp.service('youtubeAPI',function(){
return({
showMovie:movieYoutube,
});
function movieYoutube( video_url ){
var player, iframe;
// init player
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '200',
width: '342',
videoId: video_url,
events: {
'onReady': onPlayerReady,
}
});
}
// when ready, wait for clicks
function onPlayerReady(event) {
var player = event.target;
player.playVideo();
}
}
});
You should consider creating an angular service and not putting javascript in your view. But since that doesn’t answer your question....
– Vinicius Zaramella
i can use the youtube api by creating a service?
– Michel Henriq
The chance is that there should already be an implementation for what Voce wants. https://github.com/cejast/ng-youtube. And I gave you the wrong tip. In case you mess with the view the correct one is to use a Directive to manipulate what is needed in the DOM and communicate with the information that exists in the view and a Service to communicate with the external service that you are using. Finally, Directive uses the service to get the necessary data and put it in the view. Directive also processes the actions the user takes in the view relating to this Directive.
– Vinicius Zaramella
According to the service you want me to assemble, can you give me an example, this Directive thing has not yet entered my head? I understood the concept, that Directive takes the hints of the view and the service works on the external. In this service I set up, it cannot initialize the class
YT.Player
he accusesYT.Player is not definied
– Michel Henriq
You have to see where and how you are including this YT library.
– Vinicius Zaramella
Take a look at this link that I gave you with an example of how to use youtube at the angle. It uses a Service to load the youtube script.
– Vinicius Zaramella
Vinicius, I’m including the YT library directly in the service.
– Michel Henriq