1

我试图找出一个多小时的问题。我收到一个错误:

Error: Argument 'SimpleController' is not a function, got undefined

有谁知道为什么 SimpleController 未定义?谢谢!

    <!DOCTYPE html>
    <html ng-app>
    <body>
    <div ng-controller="SimpleController">
        <ul>
            <li ng-repeat="customer in customers">
                {{ customer.name }}
            </li>
        </ul>
    </div>   
    <script type="text/javascript"
            src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
    <script>
        function SimpleController($scope) {
            $scope.customers = [
                { name: 'Dave Jones', city: 'Kentucky' },
                { name: 'Mister X', :city: 'SF' }
            ];
        }
    </script>
    </body>
    </html>
4

2 回答 2

5

您的数组中有错字。删除这个冒号,它会工作

$scope.customers = [
            { name: 'Dave Jones', city: 'Kentucky' },
            { name: 'Mister X', **:** city: 'SF' }
        ];
于 2013-08-30T20:19:48.713 回答
2

Remove the : in front of :city:.

Working example: http://jsfiddle.net/colllin/aQHpb/

于 2013-08-30T20:24:04.990 回答