Angular JS不重复背景图像不工作
Angular JS no-repeat with background images not working
我是Angular.js的新手(更像是CSS/jQuery),我不知道为什么我的ng repeat不起作用;我已经在CodeSchool上完成了所有的视频教程,并认为我已经掌握了Angular-down背后的基础知识,但。。。这不会重复。完全事实上,我认为可以工作的Angular命令都不是。我无法更新ng href,无法将ng样式转换为样式,一切都一团糟。将静态样式应用于我不知道的Angular元素时是否存在问题?我是不是真的搞砸了什么?
以下是引起我如此悲伤的原因:
http://jsfiddle.net/8s8vcdxr/6/
这是我正在使用的HTML,其余的显然已经结束了:
<div ng-app="thisWebsite">
<div class="column" ng-controller="myController as control">
<section class="links"
ng-repeat="instance in control.instances"
ng-style="'background':'url(' + {instance.imageUrl} + ') no-repeat;'">
<a ng-href="{{instance.pageLink}}">
<div class="link_overlay"> {{instance.title}} </div>
</a>
</section>
</div>
</div>
我哪里错了?
有一些错误,但主要问题是脚本加载顺序不正确。
从"onLoad"更改为"No warp-in",您将看到一些新的错误。
您还应该将this.instances = pieces;
移到下面定义片段的位置。
然后你的ng风格出现了错误,你可以直接使用风格。
我纠正了你的小提琴:http://jsfiddle.net/8s8vcdxr/8/
HTML
<div ng-app="thisWebsite">
<div class="column" ng-controller="myController as control">
<div class="links"
ng-repeat="instance in control.instances"
style="background: url({{instance.imageUrl}}) no-repeat;">
<a ng-href="{{instance.pageLink}}">
<div class="link_overlay"> {{instance.title}}</div>
</a>
</div>
</div>
</div>
javascript
angular.module('thisWebsite', [])
.controller('myController', function () {
var pieces = [{
pageLink: 'http://www.google.com',
imageUrl: 'http://scitechdaily.com/images/Hubble-Space-Telescope-Image-of-Spiral-Galaxy-Messier-77-120x120.jpg',
title: 'monster truck'
}, {
pageLink: 'http://www.yahoo.com',
imageUrl: 'http://scitechdaily.com/images/new-image-of-the-Helix-nebula-120x120.jpg',
title: 'not google'
}, {
pageLink: 'http://www.stackoverflow.com',
imageUrl: 'http://www.eva.mpg.de/neandertal/press/presskit-neandertal/images/Image8_thumb.jpg',
title: 'help please'
}, {
pageLink: 'http://jsfiddle.net',
imageUrl: 'http://scitechdaily.com/images/Hubble-Space-Telescope-Image-of-Spiral-Galaxy-Messier-77-120x120.jpg',
title: 'why no work'
}];
this.instances = pieces;
});
您应该尝试在浏览器中使用调试器。会有很大帮助的,看看吧!
开始:http://plnkr.co/edit/KtBPeIWX00h37YcssODZ?p=preview
我只是重新编码了一下,因为语法有点乱。几件事:
- 对于Angular,请尝试使用它与AngularJS一起构建的Plunker
- 我走了另一条路,添加了一个图像元素来进行更清洁的装订
- 所有控制器都需要
$scope
参数 - 为了改进语法,请习惯于使用数组作为控制器参数:
app.controller('MainCtrl', ['$scope`, function($scope){};
这将防止在缩小时发生错误。一个很好的资源是[ng-annotation}(https://github.com/olov/ng-annotate)资源。
希望所有的帮助!祝你好运
相关文章:
- 引导程序转盘不工作:堆叠图像(使用rails)
- 单击水平滚动库中的图像以居中显示无法工作的功能
- 图像翻转脚本未按预期工作
- 在页面中使用了两次多个图像上传,但第一个正在工作,另一个不起作用
- JQuery图像预览无法工作
- 弹出图像无法使用jquery在html中工作
- JQuery图像滑块和CSS转换只能工作一次
- 卷轴上的视差图像和粘滞标题无法正常工作
- 图像占位符没有't的工作原理与Angular 1中的相同
- 图像看起来像一个只在firefox中工作的按钮
- flexislider无法在现场工作,图像没有旋转,但导航点正在改变
- 更改图像src-dons't工作jquery/js
- JQuery图像大小计算没有'不能在Chrome/Safari中工作
- Fancybox图像点击可以独立工作,但不能与我的其他代码一起工作
- 谷歌图书预览没有在安全的https上显示图书图像链接,但在http上工作.在Google Chrome和Touch浏览器
- Elastislide-如何使其在不同的图像宽度下工作
- Jquery只有在加载图像后才能使fadeIn工作
- 如果图像工作正常,为什么 img onerror 处理程序会执行
- 显示加载图像工作不正常
- 能够像推特一样在世界地图上使用等矩形投影,也需要为美国图像工作