Ng-Controller似乎无法正常工作

时间:2014-10-21 01:43:57

标签: javascript angularjs

Angular的新手,我认为我的ng-controller存在问题,因为它无法正常工作。我已粘贴下面的代码,但基本上该表应该填充来自CustomersController $ scope的信息,但由于某种原因不是。有人可以指导我完全解决这个问题。谢谢。

下面的HTML文件

<!DOCTYPE html>
<html ng-app>
    <head lang="en">
        <meta charset="UTF-8">
        <title>Iterating Over Data</title>
        <link href="styles.css" rel="stylesheet" type="text/css" />
    </head>

    <body ng-controller="CustomersController">
         <h2> Customers </h2>
Filter:
        <input type="text" ng-model="customerFilter.name" />
        <br />
        <br />
        <table>
            <tr>
                <th ng-click="doSort('name')">Name</th>
                <th ng-click="doSort('city')">City</th>
                <th ng-click="doSort('orderTotal')">Order Total</th>
                <th ng-click="doSort('joined')">Joined</th>
            </tr>
            <tr ng-repeat="cust in customers | filter:customerFilter | orderBy:sortBy:reverse ">
                <td>{{cust.name}}</td>
                <td>{{cust.city}}</td>
                <td>{{cust.orderTotal | currency}}</td>
                <td>{{cust.joined | date}}</td>
            </tr>
        </table>
        <br /> <span>Total Customers: {{customers.length}}</span>

        <script src="angular.js"></script>
        <script src="app/controllers/customersController2.js"></script>
    </body>
</html>

js文件位于

之下
   function CustomersController($scope) {
        $scope.sortBy = 'name';
        $scope.reverse = false;


        $scope.customers = [{
            joined: '2000-12-02',
            name: 'John',
            city: 'Chandler',
            orderTotal: 9.9956
        }, {
            joined: '1965-01-25',
            name: 'Zed',
            city: 'Las Vegas',
            orderTotal: 19.99
        }, {
            joined: '1944-06-15',
            name: 'Tina',
            city: 'New York',
            orderTotal: 44.99
        }, {
            joined: '1995-03-28',
            name: 'Dave',
            city: 'Seattle',
            orderTotal: 101.5
        }];
        $scope.doSort = function (propName) {
            $scope.sortBy = propName;
            $scope.reverse = !$scope.reverse;
        };
    }

0 个答案:

没有答案