结束了这样的事情: 我执行一个函数,当周围的角度ng-repeat块改变或者窗口调整大小时,重定位目标块。
app.directive('onFinishRender', function ($timeout) {
return {
restrict: 'A',
link: function (scope, element, attr) {
if (scope.$last === true) {
$timeout(function() {
scope.$emit('ngRepeatFinished');
});
}
}
};
});
var injectItem = function(ngRepeatFinishedEvent) {
if (typeof(ngRepeatFinishedEvent) !== "undefined") {
if (typeof(ngRepeatFinishedEvent.targetScope.item) === "undefined") {return;}
//other validation
}
var index = 2;
if (window.innerWidth < 1200) {index=1;}
if (window.innerWidth < 768) {index=0;}
var secondRow = jQuery('.items').eq(index);
var injectable = jQuery(".injectable").eq(0);
if (!secondRow.next().hasClass('injectable')) {
jQuery(".injectable:not(:first)").remove();
secondRow.after(injectable.clone().css('display', 'block'));
}
};
$scope.$on('ngRepeatFinished', injectItem);
window.addEventListener('resize', function() {
injectItem();
});
<span class="injectable" style="display: none;">sorta fixed position blah</span>
<span ng-repeat="item in items" on-finish-render class="item">
surrounding blah
</span>
这个答案是基于Calling a function when ng-repeat has finished
排除仍处于工作草案阶段,我相信,让他们的唯一方式,比如说浏览器将启用实验功能。 – 2015-01-09 20:08:01