0

我正在尝试创建一个使用 AngularJS 和 UI-Bootstrap 的 plunkr。只要我想添加“ui-bootstrap”依赖项,预览就不会评估 {{}} 绑定。事实上,只要我输入任何依赖项(“ui-bootstrap”甚至“”),代码就会失败。如果我将数组留空,一切正常。

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

那里有什么问题?

4

3 回答 3

3

在您的 plunker 中,您使用过ui-bootstrap,而文档中说要使用:ui.bootstrap

它应该是

angular.module('plunker', ['ui.bootstrap'])
于 2015-11-09T08:55:48.907 回答
1

您可以在此处找到使用手风琴的工作示例。bootstrap 没有编译手风琴的问题是由于它需要创建默认模板。仅使用链接时

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

它找不到这两个模板。因此,我下载了带模板的 angular-boostrap 代码并将其添加到 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}
];
于 2015-11-09T09:29:05.507 回答
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

于 2015-11-09T08:42:35.203 回答