我试图在ng-repeat中简单地调用一个方法,但是当我调用它时该元素不存在。
我不明白为什么或如何解决它...
ID是正确的。如果我在加载后在开发控制台中运行,则可以正常工作
$scope.buildAchievementLineFill = (achievement) => {
console.log($('#achievement-progress-' + achievement.achievementId)); // This is empty
$('#achievement-progress-' + achievement.achievementId).xmlinefill({
width: 150,
percent: achievement.unlocked ? 100 : 0,
fillWidth: 6,
gradient: true,
gradientColors: ['#10fac0', '#1cbdf9'],
speed: 2,
outline: true
});
}
<div class="badges-showcase-item column" ng-repeat="achievement in achievements">
<div class="badge-progress"
id="achievement-progress-{{achievement.achievementId}}"
ng-init="buildAchievementLineFill(achievement);">
</div>
</div>
为什么在ng-init中调用该方法时id不存在?
我怎么解决这个问题?
最佳答案
用下面的代码替换代码后再试一次
<div class="badges-showcase-item column" ng-repeat="achievement in achievements">
<div class="badge-progress" id="achievement-progress-{{achievement.achievementId}}" ></div>
{{ buildAchievementLineFill(achievement) }}
</div>