2014-11-23 213 views
0

我遇到了我的控制器問題。我試圖設置頁面加載時的默認順序,以按數字順序顯示。現在這些卡正好加載,並且可以通過選擇一個命令。 我需要一些幫助。控制器中的過濾器 - 角度

控制器:

var cardApp = angular.module('cardApp', []); 

cardApp.controller('MainController', ['$scope', function ($scope) { 

    $scope.greeting = "AngularJS Hello World!"; 
    $scope.subTitle = "AngularJS Intro"; 

    function ctrl($scope, $filter) { 
     $scope.cards = [ 
     { "number": "2", "suit": "Hearts", "numOrd": 2 }, 
     { "number": "10", "suit": "Spades", "numOrd": 10 }, 
     { "number": "5", "suit": "Spades", "numOrd": 5 }, 
     { "number": "Q", "suit": "Hearts", "numOrd": 12 } 
     ]; 
    } 
}]); 

查看:

<!doctype html> 
<html> 
    <head> 
    <title>Starting Angular</title> 
    </head> 

    <body ng-app="cardApp"> 

    <div ng-controller="MainController"> 

     <h1 ng-bind="greeting"></h1> 
     <h3 ng-bind="subTitle"></h3> 

     <span>Sort By:</span> 
     <select ng-model="orderProp"> 
     <option value="suit">Suit</option> 
     <option value="numOrd">Number</option> 
     </select> 
     <hr> 

     <table> 
     <tr> 
      <th>Number</th> 
      <th>Suit</th> 
     </tr> 

     <tr ng-repeat="card in cards | orderBy:orderProp"> 
      <td ng-bind ="card.number"></td> 
      <td ng-bind ="card.suit"></td> 
     </tr> 
     </table> 
     <br /> 

    </div> 

    <script src="http://code.angularjs.org/1.3.3/angular.min.js"></script> 
    <script src="js/controllers.js"></script> 
    </body> 
</html> 
+1

'orderProp'在哪裏? – dursk 2014-11-23 05:06:11

回答

1

定義orderProp的價值就像你的問候和字幕範圍創造的一部分。

$scope.orderProp = 'numOrd';