2013-07-12 36 views
0

我正面臨角度和基礎之間的干擾導致的錯誤。角度NG檢查干擾基礎

基本上,我只是複製粘貼the example provided in the doc

Check me to check both: <input type="checkbox" ng-model="master"><br/> 
<input id="checkSlave" type="checkbox" ng-checked="master"> 

兩種情況:

  • 時,我有$(document).foundation();:漂亮的設計,例如不工作

  • 當我評論$(document).foundation(); :沒有更多的基礎善良,實例工程

我想這是由於基金會增加了額外的標記,但仍然沒有多大幫助。

我正在尋找一種方法來解決這個問題?

回答

1

您不能在Angular驅動的DOM上調用類似.foundation()的庫初始化程序,因爲在Angular創建它們之前,DOM元素實際上不存在。

這是任何客戶端MVC框架的主要速度顛簸,但請放心,您並不是唯一希望實現此類功能的用戶。

使用Foundation with Angular的正確方法是將其小部件封裝在Directives中。

這裏有一些資源,幫助您:

+0

我只需要保持複選框設計一個這樣或那樣的。 Iguess我應該告訴基金會讓他們獨處 – apneadiving

0

您可以創建自定義指令而不是使用ng-checked,它將處理基金會的附加標記。它可能不是空閒的方式,但它會解決你的問題,因爲它知道太多關於基礎實施等

指令段從original blog post

directive('ngCheckedFoundation',['$timeout', function($timeout) { 
    function markCheckBox(value, scope, element, attr) { 
     //timeout to avoid the foundation javascript action changed by this directive 
     $timeout(function() { 
       if(value) { 
        attr.$set("checked", true); 
        element.next().addClass('checked'); 
       } 
       else { 
        attr.$set("checked", false); 
        element.next().removeClass('checked'); 
       } 
     }, 200); 
    } 

    function link (scope, element, attr, ctrl) { 
     scope.$watch(attr["ngCheckedFoundation"], function(n,o) { 
      if(n != o) { 
      markCheckBox(n, scope, element, attr); 
      } 
     }); 
     markCheckBox(scope.$eval(attr.ngCheckedFoundation), scope, element, attr); 
    } 

    return({ 
     link: link, 
     restrict: "A", 
    }); 
}])