gpt4 book ai didi

javascript - ngRepeat 完成时触发

转载 作者:行者123 更新时间:2023-11-30 10:14:25 26 4
gpt4 key购买 nike

在一个指令中,我需要一个元素的宽度,但是这个元素是在 ng-repeat 中创建的.所以当我的代码里面 link函数运行时,ngRepeat 尚未执行。我试图使用 $timeout 来延迟事情但这并没有帮助

JS:

link: function (scope, element) {
$timeout(function () {
var width = $(element.find('li')).width(); // the li elements do not exist
});
}

HTML:

<ol>
<li ng-repeat="item in items">
<my-item>.....</my-item>
</li>
</ol>

我无法使用 <ol>元素,因为 <my-item>具有边距/填充等样式。

有什么建议吗?

最佳答案

来自 ng-repeat finish event

<ol>
<li ng-repeat="item in items" on-complete>
<my-item>.....</my-item>
</li>
</ol>

-

.directive('onComplete', function() {
return function(scope, element, attrs) {
angular.element(element).css('color','blue');
if (scope.$last){
window.alert("im the last!");
}
};
})

http://plnkr.co/edit/or5mys?p=preview

关于javascript - ngRepeat 完成时触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24673548/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com