如何将全局变量数据从视图发送到控制器?

时间:2018-04-17 05:19:08

标签: javascript html angularjs html5

我的Angular视图文件如下所示。

<!DOCTYPE html>

<video id="myVideo" class="video-js vjs-default-skin"></video>
<script>
  var dataUri;
  var videoData;
    var player = videojs("myVideo", {
    controls: true,
    width: 320,
    height: 240,
    fluid: false,
    plugins: {
        record: {
            audio: true,
            video: true,
            maxLength: 100,
            debug: true
        }
    }
}, function(){
    // print version information at startup
    videojs.log('Using video.js', videojs.VERSION,
        'with videojs-record', videojs.getPluginVersion('record'),
        'and recordrtc', RecordRTC.version);
});
// error handling
player.on('deviceError', function() {
    console.log('device error:', player.deviceErrorCode);
});
player.on('error', function(error) {
    console.log('error:', error);
});
// user clicked the record button and started recording
player.on('startRecord', function() {
    console.log('started recording!');
});
// user completed recording and stream is available
player.on('finishRecord', function() {
    console.log('player : ', player.recordedData.video.name);
    videoData = player.recordedData;
    console.log('finished recording: ', player.recordedData);
}

);


function getVideoData()
{
    return videoData;
}
</script>
<button id="record" onClick="getVideoData();" ng-model="onFileSelect()"></button>

player.on(&#39; finishRecord&#39;,function()函数被调用时,它将在player.recordedData变量中记录视频数据。我的问题是什么,我想要将player.recordedData发送到按钮点击的角度控制器,其ID为记录

1 个答案:

答案 0 :(得分:0)

如果全局定义了vairiable,您可以直接在任何控制器中使用它。尝试将数据放入object.xxx格式。

示例:

var model = {videoData: null};


player.on('finishRecord', function() {
    ...
    model.videoData = player.recordedData;
}
控制器中的

//directly use it, ensure it has data
model.videoData