2012-10-24 117 views
1

我有动态标签生成(jquery-ui)与AngularJS的问题。问题与jQueryUI标签+ AngularJS

我已经创建了一个指令,用于在div标签上调用标签(jQuery-UI)初始化,该标签具有用ng-repeat生成的ul> li>元素。

我认为问题是在初始化标签的某处不与模型绑定syncronized,我得到一个奇怪的行为选项卡上。我认为可能会发生这种情况,因为模型之前的标签库的初始化“改变了”,因为我正在用ajax加载模型,而且我不知道如何处理标签小部件的“重新初始化”。

我的指令看起来像这样:

myApp.directive('juiTabs', function() { 
    return function postLink(scope, iElement, iAttrs) { 
     jQuery(function() { 
      $(iElement).tabs(); 
     }); 

    } 
}); 

我的控制器

function MyCtrl($scope, $locale, $routeParams, $http) { 

    $scope.DataSource = null; 

    $http({ 
     url: "/api/product/1", 
     method: "GET", 
     data: { "foo": "bar" } 
    }).success(function (data, status, headers, config) { 

     if (data.isSucess) { 
      $scope.DataSource = data.Data; 
     } 
     else { 
      NotifyError("..."); 
     } 
    ... 

有谁有一些想法如何可以强制标签的重新初始化我的模型更改后?

+3

我甚至不会使用JQuery UI选项卡。你可以用Angular创建你自己的,用JQuery UI的css风格。 –

+0

我怀疑他们不能一起工作,因为jquery-ui标签和Angularjs通过拦截哈希标签 –

回答

1

尝试在你的指令,这样的“看”你的模型:

myApp.directive('juiTabs', function() { 
    return function postLink(scope, iElement, iAttrs) { 
     scope.$watch(iAttrs.ngModel, function (newValue) { 
      jQuery(function() { 
       $(iElement).tabs(); 
      }); 
     } 
    } 
});