2016-03-27 11 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: '/' }); 
    }); 
}()); 

işlemek için başarısız olur. Aşağıda ng bakışı, <code>/app/app.js</code> ve <code>/app/views/customers.html</code><code>/app/customersController.js</code> sahip

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> 

ve burada kontrolör geçerli:

(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 aşağıdaki gibidir: Bu yük customers.html doesnt

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> 

, let Üstte tek başına test metin.

Sorun nerede?

cevap

2

Modülünüzü yeniden tanımlıyorsunuz. Buna bu satırı

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

değiştirmeyi deneyin:

angular.module('app').controller('customersController', customersController); 
İlgili konular