2015-11-09 21 views
0

我正在嘗試創建一個使用AngularJS和UI-Bootstrap的plunkr。只要我想添加「ui-bootstrap」依賴項,預覽就不會評估{{}}綁定。事實上,隨着我輸入任何依賴項(「ui-bootstrap」或甚至「」),代碼失敗。如果我把數組留空,一切正常。無法在plunkr中添加角度應用依賴項

angular.module("myApp", [/*leaving this empty works, otherwise bindings wont be resolved*/]).controller("myCtrl", function ($scope) { 
     //controller stuff 
    } 
]); 

http://plnkr.co/edit/38sWnHVSS3lfYSB5oPzp?p=preview

有什麼不對呢?

回答

3

在你plunker你已經使用ui-bootstrap,而文件說,使用方法:ui.bootstrap

應該

angular.module('plunker', ['ui.bootstrap']) 
+0

Woops ...你是對的。無論如何,如果我改變這種情況,掠奪者不會顯示任何預覽:o某些東西似乎仍然是錯誤的。 – Fidel90

+0

好吧,明白了。我也有ui-bootstrap cdn路徑錯誤。現在它工作正常:http://plnkr.co/edit/QocibRNIGFl1DkdGzVnZ?p=preview謝謝:) – Fidel90

0

我看了一下,看起來你的嵌套方式太多了。

$scope.MainCtrl = { 
     groups : [ 
     {heading: "A", content: "This is the first accordion group", opened:true}, 
     {heading: "B", content: "This is the second accordion group", opened: false}, 
     {heading: "C", content: "This is the last accordion group", opened:false} 
     ] 
    }; 

在這裏,我們定義MainCtrl作爲一個新的對象,然後裏面嵌套組。

angular.module('plunker', []) 
    .controller('MainCtrl', function($scope) { 
    $scope.groups = [ 
     {heading: "A", content: "This is the first accordion group", opened:true}, 
     {heading: "B", content: "This is the second accordion group", opened: false}, 
     {heading: "C", content: "This is the last accordion group", opened:false} 
    ]; 

    }); 

工作:http://plnkr.co/edit/Le2awE24GJiM3N6h8uQO?p=preview

+0

正如你可以在這裏看到,我已刪除了內部嵌套。現在,您需要將'groups'定義爲可用於範圍的直接對象;在你的代碼中,它不是。然而,修復是微不足道的,你可以弄清楚我已經做了什麼! :) – weirdpanda

+0

嗨,感謝您的關注。不幸的是,這不是問題。嘗試添加一個像「ui-bootstrap」這樣的依賴關係到角度應用程序,它會打破綁定:http://plnkr.co/edit/gTAhW1PGCEABYYw5n6dl?p=preview – Fidel90

+2

@ Fidel90它將「ui.bootstrap」作爲依賴項。檢查https://angular-ui.github.io/bootstrap/#/getting_started –

1

的工作與地方accortion例如,你可以找到here。 引導程序未編譯失敗的問題是由於創建所需的默認模板。當只使用鏈接

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.14.3/ui-bootstrap.js"></script> 

它找不到這兩個模板。所以我下載了angular-boostrap代碼WITH模板並將它添加到注入了依賴關係的plunkr +中,並且它正常工作。 請注意,嵌套建議移除在這個例子中也完成的,所以在控制器只有:

$scope.groups = [ 
    {heading: "A", content: "This is the first accordion group", opened:true}, 
    {heading: "B", content: "This is the second accordion group", opened: false}, 
    {heading: "C", content: "This is the last accordion group", opened:false} 
];