Angular.js指令函数在控制器中返回值

时间:2014-07-01 12:06:39

标签: javascript jquery angularjs angularjs-directive

我的指令有问题。 在我的指令中,我有一个init()视频播放器操作插件。 现在在我的HTML中我有2个按钮: 播放视频 马尔()

我希望用户点击markIn()按钮指令将markin值返回给控制器。 这怎么样? 我是angular.js中的大三学生

提前致谢

指令代码

    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

            }
        }

    }
});

控制器代码

 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>

0 个答案:

没有答案