Angularjs未定义函数错误:ng:areq Bad Argument

时间:2016-01-13 12:36:29

标签: angularjs angularjs-directive angularjs-scope angularjs-ng-repeat

我正在从视频教程中学习angularjs的婴儿步骤,当我到达控制器部分时,我遇到了这个错误:

  

Argument' SimpleController'不是一个功能,未定义

虽然我仔细地按照步骤操作。请记住这是迄今为止我对angularjs的所有了解。

<!DOCTYPE html>
<html data-ng-app="">
    <head></head>

    <body>
        <div data-ng-controller="SimpleController">
            <input type="text" data-ng-model="name" id=""> {{ name }}

            <br>

            <h3>Looping with the ng-repeat Directive</h3>

            <ul>
                <li data-ng-repeat="cutomer in customers | filter:name | orderBy:'city'">{{ cutomer.name | uppercase }} - {{ cutomer.city | lowercase }}</li>
            </ul>
        </div>

        <script src="angular.min.js"></script>
        <script>
            function SimpleController($scope) {
                $scope.customers = [
                    {name:'Yasser Moussa',city:'Alexandria'},
                    {name:'Ahmed Salah',city:'Al Riyadh'},
                    {name:'Khaled Medhat',city:'Alexandria'},
                    {name:'Ali Dawood',city:'Cairo'}
                ];
            }
        </script>
    </body>
</html>

1 个答案:

答案 0 :(得分:1)

  1. 创建一个名为&#34; app&#34;
  2. 的模块
  3. 使用控件将控件分配给该模块 angular.module("app", []).controller("SimpleController, function() {})
  4. 使用data-ng-app="app"
  5. 在html中声明模块

    这是plunker