gpt4 book ai didi

javascript - 如何在 ng-repeat 期间呈现 {{ }}?

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

考虑以下指令:

.directive('otherDirective', function(){
return {
link: function(scope, elem, attr){
console.log(elem[0]);
alert(elem[0]);
}

}

如果我将它应用到 ng-repeat 标记中,我会注意到 {{item}} 直到 ng-repeat 结束(当被 alert() 阻止时)才会被评估。如何在每次“循环”后渲染它?

因为在实际场景中,这些项目包含一个图像,我想在每个图像加载后进行回调,但没有 img url 我无法绑定(bind)事件。

here is the plunker

最佳答案

使用$timeout 等待ng-repeat 完成:Plunker

.directive('otherDirective',['$timeout', function($timeout){
return {
link: function(scope, elem, attr){
$timeout(function () {
console.log(elem[0]);
alert(elem[0]);
});
}
};
}]);

关于javascript - 如何在 ng-repeat 期间呈现 {{ }}?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32258261/

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