我正在使用 AngularJS 并尝试使用 http://welldonethings.com/tags/manager 制作标签管理器指令。问题是,当调用 jQuery 插件时,标签输入和名称输入还没有 {{index}} 值。我该如何解决它?
我的 HTML 代码:
<div ng-repeat="(index, title) in shop.locales" style="position: relative">
<span> {{ title }}</span>
<div class="input-block">
<input tags prefilled="product.tags[index]" tags-options="{hiddenTagListName: scope.locale+'_tagList'}" locale="index" class="{{index}} tag tm-input" name="{{ index }}_tags" placeholder="Tags"/>
</div>
</div>
还有 JS:
app.directive('tags', function(){
return {
restrict: 'EA',
scope: { prefilled: '=prefilled', locale: '=locale'},
link: function(scope, element, attrs) {
scope.$watch('prefilled', function(prefilled) {
if(prefilled){
angular.forEach(prefilled,function(data){
element.tagsManager('pushTag',data);
})
}
return element.tagsManager(scope.$eval(attrs.tagsOptions));
})
}
}
});
最佳答案
您是否尝试过以零延迟将逻辑包装在 $timeout
回调中?
像这样:
$timeout(function yourLogicHere() {}, 0);
此回调应该在 $digest
循环之后调用,因此所有数据都应该已经绑定(bind)到 DOM。
关于jquery - ng-repeat 数据加载后如何加载 jQuery 插件指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17557905/