passing scope value to javascript function

1

How do I pass $scope.video_url to a javascript function in my view?

I have a service that returns me the id of a video, and in my view I have a javascript infonation that starts the youtube player according to this id, but how do I pass that id to the function? >

I created a service, but the video did not appear 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();
        }
    }
});
    
asked by anonymous 22.03.2016 / 19:12

1 answer

1

You can use the angle inside your script in the view directly because it is defined globally.

<div ng-controller="AlgumCtrl" id="ctrlID"></div>
<script>
    function foo(){
        var scope = angular.element('#ctrlID').scope();
        var video_url = scope.video_url;
        //faça algo
    }
 </script>
    
22.03.2016 / 20:15