2

我正在使用 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));
            })

        }
    }
});
4

1 回答 1

0

您是否尝试将逻辑包装在$timeout零延迟的回调中?

像这样:

$timeout(function yourLogicHere() {}, 0);

这个回调应该在$digest循环之后调用,所以所有数据应该已经绑定到 DOM。

于 2013-09-04T16:10:42.650 回答