2016-02-04 41 views
0

我的代碼中有什麼錯誤? cust.namecust.city不顯示。ng-repeat沒有在無序列表中創建列表項

爲什麼沒有創建列表項?

<html> 
    <body> 
     <div data-ng-controller="SimpleController"> 
      Name : 
      <br /> 
      <input type="text" data-ng-model="name" placeholder="Enter Your Name " /> {{ name }} 
      <br /> 

      <ul> 
       <li data-ng-repeat="cust in customers | filter:name | orderBy:'city' "> 
        {{ cust.name | uppercase }} - {{ cust.city | lowercase }} 
       </li> 
      </ul> 
     </div> 
     <script src="angular.min.js"></script> 
     <script> 
      function SimpleController($scope) { 
       $scope.customers = [ 
        { 
         name: 'Rishabh Shrivas', 
         city: 'New Delhi' 
        }, 
        { 
         name: 'Rishabh Bharadawaj', 
         city: 'Noida' 
        }, 
        { 
         name: 'Rishabh Sen', 
         city: 'Gurgaon' 
        } 
       ]; 
      } 
     </script> 
    </body> 
</html> 

回答

0

您需要在HTML的ng-app部分,甚至連空的就足夠了。另外,您需要以不同的方式創建控制器:

var myApp = angular.module('myApp',[]); 
myApp.controller('SimpleController', ['$scope', function($scope) { 
    $scope.customers = [ 
     { 
      name: 'Rishabh Shrivas', 
      city: 'New Delhi' 
     }, 
     { 
      name: 'Rishabh Bharadawaj', 
      city: 'Noida' 
     }, 
     { 
      name: 'Rishabh Sen', 
      city: 'Gurgaon' 
     } 
    ]; 
}]);