2016-03-27 48 views
0
//app.js 
(function() { 
    var app = angular.module('app', ['ngRoute']); 

    app.config(function ($routeProvider) { 

     $routeProvider.when('/', 
     { 
      controller: 'customersController', 
      templateUrl: '/app/views/customers.html' 
     }).otherwise({ redirectTo: '/' }); 
    }); 
}()); 

我有/app/app.js/app/views/customers.html/app/customersController.jsng-view无法呈现

下面是HTML

<!DOCTYPE html> 
<html ng-app="app"> 
<head> 
</head> 
<body> 

    <div class="container body-content"> 

     <div class="row"> 
      <div class="col-md-12"> 
       <div ng-view></div> 
      </div> 
     </div> 




    </div> 

    <script src="/Assets/Scripts/jquery-1.10.2.js"></script> 

    <script src="/Assets/Scripts/bootstrap.js"></script> 
<script src="/Assets/Scripts/respond.js"></script> 

    <script src="/Assets/Scripts/angular.min.js"></script> 
    <script src="/Assets/Scripts/angular-route.min.js"></script> 
    <script src="/app/app.js"></script> 
    <script src="/app/customersController.js"></script> 

</body> 
</html> 

这里是控制器:

(function() { 

    var customersController = function customersController($scope) { 
     $scope.sortBy = 'name'; 
     $scope.reverse = false; 


     $scope.customers = [{ name: 'foo', city: 'ny' }, { name: 'bar', city: 'la' }]; 

     $scope.doSort = function (propname) { 
      $scope.sortBy = propname; 
      $scope.reverse = !$scope.reverse; 
     }; 
    }; 

    customersController.$inject = ['$scope']; 
    angular.module('app', []).controller('customersController', customersController); 

}()); 

customers.html客户如下:

test 


<div> 
    <table> 
     <tr> 
      <td>Name</td> 
      <td>City</td> 
     </tr> 

     <tr ng-repeat="customer in customers "> 
      <td>{{customer.name}}</td> 
      <td>{{customer.city}}</td> 
     </tr> 
    </table> 
</div> 

它不负载customers.html客户,让单独上test文字。

问题在哪里?

回答

2

我认为你正在重新定义你的模块。 尝试改变这一行

angular.module('app', []).controller('customersController', customersController); 

这样:

angular.module('app').controller('customersController', customersController);