Data-src标签在index.html中工作,但在angular视图中不起作用
data-src tags working in index.html, but not working in angular views
我对angular和javascript比较陌生,所以如果我听起来很愚蠢,请接受我的道歉。
我正在尝试将一个主题合并到angular。我注意到,如果我将整个代码包含到index.html中,网站可以工作,但是当我将代码转移到控制器并通过<div ui-view></div>
调用它们时,渲染的页面会错过一些关键组件。
例如,下面会导致播放标题背景视频:
<img src="img/video_fix.png" alt="" class="header-video--media" data-video-src="video/intro" data-teaser-source="video/intro" data-provider="Vimeo" data-video-width="1920" data-video-height="960">
如果我将它包含在index.html中,它工作得很好。但如果我把它包含在控制器中,它就不会渲染了。
另一个不渲染的代码:
<section class="parallax-window" data-parallax="scroll" data-image-src="img/bg_office.jpg" data-natural-width="1200" data-natural-height="600">
经过搜索,我知道你不能直接在视图中包含jQuery插件,但必须在指令中这样做。然而,我还没有找到任何指南,可以让我了解如何在angular视图中合并jQuery插件。
index.html中包含以下代码:
<script src="js/video_header.js"></script>
<script>
$(document).ready(function () {
'use strict';
HeaderVideo.init({
container: $('.header-video'),
header: $('.header-video--media'),
videoTrigger: $("#video-trigger"),
autoPlayVideo: true
});
});
</script>
下面是video_header.js的代码
var HeaderVideo = function (e, i) {
var o = {
container: e(".header-video"),
header: e(".header-video--media"),
videoTrigger: e("#video-trigger"),
videoCloseTrigger: e("#video-close-trigger"),
teaserVideo: e("#teaser-video"),
autoPlayVideo: !1
}, r = function (i) {
o = e.extend(o, i), t(), d(), a(), o.videoCloseTrigger.hide(), videoDetails.teaser && n(), o.autoPlayVideo && l()
}, t = function () {
return videoDetails = {
id: o.header.attr("data-video-src"),
teaser: o.header.attr("data-teaser-source"),
provider: o.header.attr("data-provider").toLowerCase(),
videoHeight: o.header.attr("data-video-height"),
videoWidth: o.header.attr("data-video-width")
}, videoDetails
}, d = function () {
o.container.data("aspectRatio", videoDetails.videoHeight / videoDetails.videoWidth), e(window).resize(function () {
var i = e(window).width(), r = e(window).height();
o.container.width(i).height(i * o.container.data("aspectRatio")), r < o.container.height() && o.container.width(i).height(r)
}).trigger("resize")
}, a = function () {
o.videoTrigger.on("click", function (e) {
e.preventDefault(), l(), o.videoCloseTrigger.fadeIn()
}), o.videoCloseTrigger.on("click", function (e) {
e.preventDefault(), s()
})
}, n = function () {
if (Modernizr.video && !f()) {
var e = videoDetails.teaser, i = '<video autoplay="true" loop="loop" muted id="teaser-video" class="teaser-video"><source src="' + e + '.mp4" type="video/mp4"><source src="' + e + '.ogv" type="video/ogg"></video>';
o.container.append(i)
}
}, v = function () {
if ("youtube" === videoDetails.provider)var e = '<iframe id="video" src="http://www.youtube.com/embed/' + videoDetails.id + '?rel=0&hd=1&autohide=1&showinfo=0&autoplay=1&enablejsapi=1&origin=*" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>'; else if ("vimeo" === videoDetails.provider)var e = '<iframe id="video" src="http://player.vimeo.com/video/' + videoDetails.id + '?title=0&byline=0&portrait=0&color=3d96d2&autoplay=1" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>'; else if ("html5" === videoDetails.provider)var e = '<video autoplay="true" loop="loop" id="video"><source src="' + videoDetails.id + '.mp4" type="video/mp4"><source src="' + videoDetails.id + '.ogv" type="video/ogg"></video>';
return e
}, l = function () {
o.header.hide(), o.container.append(v()), c(), o.teaserVideo.hide()
}, s = function () {
e("#video").remove(), o.teaserVideo.fadeIn(), u(), g()
}, c = function () {
o.videoTrigger && o.videoTrigger.fadeOut("slow")
}, u = function () {
o.videoTrigger && o.videoTrigger.fadeIn("slow")
}, g = function () {
o.videoCloseTrigger.hide()
}, f = function () {
return e(window).width() < 900 && Modernizr.touch ? !0 : !1
};
return {init: r}
}(jQuery, document);
将jquery代码移动到控制器中。在angular之外单独使用jquery是行不通的。还要确保jquery是在angular之前加载的。把jquery和angular混在一起并不是一个好习惯,因为angular可以做很多事情,而且内置了jquery。
相关文章:
- 我的shareService在angular 2中发送值工作正常,但当我渲染我的另一个组件时,会获得默认值
- 预期响应包含一个对象,但在angular js中得到一个数组错误
- 保持状态打开”;在背景中”;.隐藏,但不要't在Angular UI中离开状态
- Angular http在Phone gap中返回错误,但在浏览器中成功
- $cacheFactory removeAll() 在服务中的单元测试在 Angular 1.2.0 中失败,但在 1.
- Angular / nodejs ng-file-upload - 文件加载在 angular 上,但在 nodejs
- ng-click事件在ionic中不起作用,但它在Angular中起作用
- 变量在$scope中可见,但在 Angular 中实际访问时未定义
- 使用Express angularJs和mongoDB,但在angular中使用ngResource不加载
- Angular Meteor应用程序在localhost中工作,但在部署到服务器时失败
- ng模式,该模式允许字母数字,但在angular js中没有用于输入标签的空格
- 链接在broswer中工作,并提供JSON,但在Angular中则不然
- php-json:encode在服务器上的angular控制器上的http调用中返回undefined,但在localh
- 我在angular js中调用一个数据抛出json,但不接收数据为什么
- Angular JS,工厂返回数据,但在控制器中它消失了
- Angular JS在Safari中会中断,但在Chrome中不会
- Angular指令mouseenter/mouseleave正在工作,但在mouseleave之后不会设置为初始状态
- 在Angular 1.5中,track by不能与order by一起工作——期望的数组,但收到了
- 可排序的Angular数据表——可排序的表在第一次加载时呈现良好,但在后续过滤器中不产生记录
- Data-src标签在index.html中工作,但在angular视图中不起作用