Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a problem with directive. In my directive i have init() a video player manipulation plugin. Now in my html i have 2 buttons: playVideo markIn()

I want that user click on markIn() button directive return markin value to controller. How ca do this? I'm junior in angular.js

Thanks in advance

DIRECTIVE CODE

    mwm3.directive('videoPlayer', function() {
    return{
        restrict: 'E',
        link: function(scope, element, attrs) {
            var myPlayer = angular.element(document.querySelector('#videoPlayer'));
            element = VideoFrame({
                id: myPlayer,
                frameRate: 25,
                callback: function(response) {
                    console.log('response');
                }
            });
            scope.playVideo = function() {
                //play video function
                element.video.play();
            }

             scope.markIn = function() {
                //markIn time
                var markIn= element.toSMPTE();
                //here i want return this value to my controller when user click on button ng-click="markIn()" in directive

            }
        }

    }
});

CONTROLLER CODE

 mwm3.controller('TestPlayerCtrl', function($scope) {
    $scope.markIn = function(valueFromDirective) {
     //here i want value Mrkin from directive MarkIn function when user click on markIn button
        console.log(valueFromDirective);
    };
});

HTML CODE

        <video id="videoPlayer" width="100%" controls src="asset/tc3.mp4" type="video/mp4"></video>
    </section>

    <section id="videoControls">
        <div class="row more-margin-bottom">
            <div class="col-sm-12">
                <button ng-click="playVideo()" class="btn btn-large btn-inverse"><i class="fa fa-play-circle fa-2x"></i></button>
                <button ng-click="markIn()" class="btn btn-large btn-inverse"><i class="fa fa-pause fa-2x"></i></button>
            </div>
        </div>
    </section>
</video-player>
share|improve this question
    
If you really need this, you can use events. Take a look at the $broadcast, and $emit services. But why do you need to do this? –  cuttlas Jul 1 at 12:17
    
Becaouse in my controller I have a service that send markIn time to websoket. –  user3790694 Jul 1 at 12:29
    
Why not just call the controllers method from your directive? 'scope.markIn(value)'. Directives inherit scope when scope is not defined. –  Ben Felda Jul 1 at 12:46
    
Yes is good idea... How can do id? –  user3790694 Jul 1 at 14:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.