简体   繁体   English

AngularJS Library仅在刷新页面后才起作用,如果我改变状态则停止工作

[英]AngularJS Library only works after I refresh the page, if I change states it stops working

I'm using a library video.js . 我正在使用图书馆video.js I used the example code from the website: 我使用了网站上的示例代码:

<video id="my-video" class="video-js vjs-default-skin" controls 
preload="auto" width="1000" height="600" data-setup='{ "playbackRates": [1, 
1.5, 2] }'>
         <source src="file\undefined\1501667652598.mp4" type="video/mp4">
</video>

and added the scripts/css: 并添加了scripts / css:

<link href="http://vjs.zencdn.net/6.2.4/video-js.css" rel="stylesheet">
<script src="http://vjs.zencdn.net/6.2.4/video.js"></script>

When I straight refresh the page, it works fine. 当我直接刷新页面时,它工作正常。 But if I change states, it defaults to the regular video player. 但如果我改变状态,它默认为常规视频播放器。 What could be the problem I'm facing? 我面临的问题可能是什么?

States definition looks like that: 国家定义看起来像这样:

angular.module("pamm").config(function ($stateProvider) {
    $stateProvider
        .state("user.topic", {
            url: "/topic",
            views: {
                "content@user": {
                    templateUrl: "feature/user/topic/topic-list.html"
                }
            },
            params: {
                section: null,
                type: null
            }
        })
        .state("user.topic.details", {
            url: "/details/:id",
            views: {
                "content@user": {
                    templateUrl: "feature/user/topic/topic-details.html"
                }
            },
            params: {course: null}
        })
        .state("user.topic.result", {
            url: "/result",
            views: {
                "content@user": {
                    templateUrl: "feature/user/topic/topic-result.html"
                }
            }
        })
});

You need to setup your player manually by calling its function if the <video> tag is only added after the page load complete. 如果仅在页面加载完成后添加<video>标记,则需要通过调用其函数手动设置播放器。

The reason is video.js will scan your HTML and setup any existing <video> tags automatically, but unfortunately it cannot watch changes in your HTML when angular updates it. 原因是video.js将扫描您的HTML并自动设置任何现有的<video>标签,但不幸的是,当角度更新时,它无法观察HTML中的更改。 ( reference ) 参考

You can add the manual setup code inside a route controller. 您可以在路径控制器中添加手动设置代码。

Just put your code inside this: 把你的代码放在这里:

jQuery.noConflict();
        (function ($) {

       //your code

})(jQuery);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我刷新页面时 JavaScript 停止工作 - JavaScript stops working when I refresh page window.onbeforeunload仅在刷新页面后有效 - window.onbeforeunload only works after i refresh the page 我的javascript函数只有在我刷新页面后才能工作 - My javascript function works only after I hard refresh the page 如果我更改页面,则tampermonkey脚本将停止工作 - tampermonkey script stops working if I change the page JavaScript 和 php 在一段时间后停止工作,只有在我重命名一些变量时才有效 - JavaScript and php stops working after some time and only works if i rename some variables jQuery插件在window.resize之后无法正常工作,但是在刷新整页后仍然可以正常工作 - Jquery plugin stops working correctly after window.resize, but works well after full page refresh 页面刷新后jquery停止工作 - After page refresh jquery stops working 道具仅在我刷新页面后呈现 - Props only render after I refresh the page jQuery函数无法在页面加载时触发,仅在刷新页面或再次重新访问同一页面后才起作用 - JQuery Function not firing on page load it works only after i refresh page or re-visit the same page again ng-class条件有效,但仅当我刷新页面时 - ng-class condition works, but only when I refresh the page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM