[英]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.