不是函数,未定义

时间:2013-08-30 20:15:07

标签: angularjs

我试图找一个问题超过一个小时。我收到了一个错误:

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>

2 个答案:

答案 0 :(得分:5)

您的阵列中有拼写错误。删除这个冒号,它将起作用

$scope.customers = [
            { name: 'Dave Jones', city: 'Kentucky' },
            { name: 'Mister X', **:** city: 'SF' }
        ];

答案 1 :(得分:2)

删除:前面的:city:

工作示例: http://jsfiddle.net/colllin/aQHpb/