jquery - ng-repeat 数据加载后如何加载 jQuery 插件指令

标签 jquery angularjs angularjs-directive angularjs-ng-repeat

我正在使用 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/

相关文章:

javascript - 如何将单选按钮的属性设置为选中

javascript - 指令中的 AngularJS 模板与 templateURL

javascript - AngularJS 指令的 link() 函数中的 DOM 元素未准备好

javascript - 检查选择下拉列表中的选项是否可用

javascript - Jquery字符串替换,仅替换数组的开头

jQuery Marquee 滚动文本在 Bootstrap Modal 中不起作用

javascript - jQuery.dataTable() 如何隐藏行?

javascript - 将行为传递给指令的正确 "Angular"方法?

angularjs - 如何管理不是通过打字下载的类型定义文件?

AngularJS:错误:没有 Controller :表单