[Angularjs]angular ng-repeat与js特效加载先后导致的问题

前端之家收集整理的这篇文章主要介绍了[Angularjs]angular ng-repeat与js特效加载先后导致的问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

@H_403_0@写在前面
<p style="margin-left: 30px;">最近在项目中遇到这样的一个前端的bug,在ng-repeat中绑定的图片,有一个晃动的特效,在手机端浏览的时候,图片有时候会正常展示,有时就展示不出来。当时猜测是因为angularjs与特效的那些代码加载的先后顺序造成的。有了这样的猜测,就有查找解决方案的方向了。


@H_403_0@系列文章
<p style="margin-left: 30px;"><a id="cb_post_title_url" class="postTitle2" href="http://www.cnblogs.com/wolf-sun/p/4614532.html"&gt;[Angularjs]ng-select和ng-options


<p style="margin-left: 30px;"><a id="cb_post_title_url" class="postTitle2" href="http://www.cnblogs.com/wolf-sun/p/4620150.html"&gt;[Angularjs]ng-show和ng-hide


<p style="margin-left: 30px;"><a id="cb_post_title_url" class="postTitle2" href="http://www.cnblogs.com/wolf-sun/p/4621854.html"&gt;[Angularjs]视图和路由(一


<p style="margin-left: 30px;"><a id="cb_post_title_url" class="postTitle2" href="http://www.cnblogs.com/wolf-sun/p/4638029.html"&gt;[Angularjs]视图和路由(二


<p style="margin-left: 30px;"><a id="cb_post_title_url" class="postTitle2" href="http://www.cnblogs.com/wolf-sun/p/4640725.html"&gt;[Angularjs]视图和路由(三


<p style="margin-left: 30px;"><a id="cb_post_title_url" class="postTitle2" href="http://www.cnblogs.com/wolf-sun/p/4656216.html"&gt;[Angularjs]视图和路由(四


<p style="margin-left: 30px;"><a id="cb_post_title_url" class="postTitle2" href="http://www.cnblogs.com/wolf-sun/p/4676116.html"&gt;[Angularjs]ng-class,ng-class-even,ng-class-odd


<p style="margin-left: 30px;"><a id="cb_post_title_url" class="postTitle2" href="http://www.cnblogs.com/wolf-sun/p/4713028.html"&gt;[Angularjs]单页应用之分页


<p style="margin-left: 30px;"><a id="cb_post_title_url" class="postTitle2" href="http://www.cnblogs.com/wolf-sun/p/4732942.html"&gt;[Angularjs]国际化


<p style="margin-left: 30px;"><a id="cb_post_title_url" class="postTitle2" href="http://www.cnblogs.com/wolf-sun/p/4749854.html"&gt;[Angularjs]ng-repeat中使用ng-model遇到的问题


<p style="margin-left: 30px;"><a id="cb_post_title_url" class="postTitle2" href="http://www.cnblogs.com/wolf-sun/p/4752004.html"&gt;[Angularjs]过滤器


<p style="margin-left: 30px;"><a href="http://www.cnblogs.com/wolf-sun/p/4781673.html" target="blank">[Angularjs]ng-file-upload上传文件


@H
403_0@解决方
<p style="margin-left: 30px;">自定义一个指令,在加载完成angular repeat时,然后再去绑定那些特效。具体如下所示:


<div class="cnblogs_code" style="margin-left: 30px;">

 app = angular.module(,[,,<span style="color: #008000;">//<span style="color: #008000;">指令
app.directive(<span style="color: #800000;">'
<span style="color: #800000;">onFinishRenderFilters
<span style="color: #800000;">'
<span style="color: #000000;">,function ($timeout) {
<span style="color: #0000ff;">return
<span style="color: #000000;"> {
restrict:
<span style="color: #800000;">'
<span style="color: #800000;">A
<span style="color: #800000;">'
<span style="color: #000000;">,link: function (scope,element,attr) {
<span style="color: #0000ff;">if
(scope.$last === <span style="color: #0000ff;">true<span style="color: #000000;">) {
$timeout(function () {
scope.$emit(<span style="color: #800000;">'<span style="color: #800000;">ngRepeatFinished<span style="color: #800000;">'<span style="color: #000000;">);
});
}
}
}
});

标签上面添加这样的代码

= id= ng-repeat= on-finish-render-filters>

添加angular repeat执行完成的回调方法

$scope.$on( h =).css(,(h / ) - +
@H_403_0@总结

猜你在找的Angularjs相关文章