使用.config时,AngularJS模块停止工作

时间:2015-12-13 05:04:18

标签: angularjs

当我创建没有任何.config的角度模块时,它可以工作。然后当我尝试添加.config来配置路由提供程序时,它不起作用。这是为什么?下面是代码示例和结果图片。我正在使用UIBootstrap。

这有效:

lst1 <- lapply(lst, function(x){
          gr1 <- cumsum(!is.na(x[-1, 'assembly_id']))
          do.call(rbind, 
            lapply(split(x[-1,], gr1), 
                 function(y) rbind(x[1,], y)))})

res <- do.call(rbind, lst1)
row.names(res) <- NULL

enter image description here

这不起作用:

angular.module('app', ['ui.bootstrap'])


    .controller('mainController', function($scope) {

      // BUTTONS ======================

      // define some random object
      $scope.bigData = {};

      $scope.bigData.breakfast = false;
      $scope.bigData.lunch = false;
      $scope.bigData.dinner = false;

      // COLLAPSE =====================
      $scope.isCollapsed = false;

    });

enter image description here

这是我的index.html文件:

angular.module('app', ['ui.bootstrap'])


.controller('mainController', function($scope) {

  // BUTTONS ======================

  // define some random object
  $scope.bigData = {};

  $scope.bigData.breakfast = false;
  $scope.bigData.lunch = false;
  $scope.bigData.dinner = false;

  // COLLAPSE =====================
  $scope.isCollapsed = false;

})
.config(function ($routeProvider) { 
  /*$routeProvider 
    .when('/', { 
      controller: 'HomeController', 
      templateUrl: 'home.html' 
    }) 
    .otherwise({ 
      redirectTo: '/' 
    }); */
}); 

这是错误:

未捕捉错误:[$ injector:modulerr] http://errors.angularjs.org/1.4.8/ $ injector / modulerr?p0 = app&amp; p1 =错误%3A%20%... ogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular .min.js%3A41%3A249)(匿名函数)@ angular.js:38(匿名函数)@ angular.js:4458n @ angular.js:340g @ angular.js:4419eb @ angular.js:4344c @ angular。 js:1676yc @ angular.js:1697Zd @ angular.js:1591(匿名函数)@ angular.js:29013b @ angular.js:3057If @ angular.js:3346Hf.d @ angular.js:3334

1 个答案:

答案 0 :(得分:0)

这对我有用,复制并粘贴它,并确保你的ng-route被注入你的应用程序。

&#13;
&#13;
<!DOCTYPE html>
<html lang="en">
<head>
    <title>My ParseApp site</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="/Content/ui-bootstrap-csp.css" rel="stylesheet" />
    <link href="/Content/bootstrap.css" rel="stylesheet" />
    <script src="/Scripts/angular.js"></script>
    <script src="/Scripts/angular-route.js"></script>
    <script src="/Scripts/angular-ui/ui-bootstrap.js"></script>
    <script src="script.js"></script>
</head>
<body>
    <div class="container" ng-app="app" ng-controller="mainController">

        <div class="text-center">
            <p class="text-success">Example of using UI Bootstrap to create responsive html elemnts that are data-bound</p>
        </div>

        <h2>Buttons</h2>
        <div class="btn-group" data-toggle="buttons">
            <label class="btn btn-primary" ng-model="bigData.breakfast" btn-checkbox>
                Breakfast
            </label>
            <label class="btn btn-primary" ng-model="bigData.lunch" btn-checkbox>
                Lunch
            </label>
            <label class="btn btn-primary" ng-model="bigData.dinner" btn-checkbox>
                Dinner
            </label>
        </div>

        <pre><code>{{ bigData | json }}</code></pre>

        <h2>Collapse</h2>

        <a href="#" class="btn btn-primary" ng-click="isCollapsed = !isCollapsed">
            Toggle Panel
        </a>

        <div class="panel panel-default">
            <div class="panel-heading">
                <h4 class="panel-title">
                    <a href="#" ng-click="isCollapsed = !isCollapsed">
                        Collapsible Group Item #1
                    </a>
                </h4>
            </div>
            <div collapse="isCollapsed">
                <div class="panel-body">
                    Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt
                    you probably haven't heard of them accusamus labore sustainable VHS.
                </div>
            </div>
        </div>

        <pre><code>{{ isCollapsed }}</code></pre>

    </div>
</body>
</html>
&#13;
&#13;
&#13;