Angular JS错误:错误:areq Bad Argument

时间:2015-03-01 04:48:40

标签: javascript angularjs

<!DOCTYPE html>
<html ng-app>
<body  data-ng-controller="SimpleController">
    <div class="container">


        Name:
        <br/>
        <input type="text" ng-model="name" />{{name}}

        <br/>

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

    </div>

    <script src="angular.min.js" ></script>
    <script>
        function SimpleController($scope)
        {
            $scope.customers = [
                { name: 'Joe', city: 'Seattle'},
                { name: 'Jack', city: 'Dallas'},
                { name: 'Jason', city: 'Houston'}
            ];
        }       
    </script>               
</body>

我正在关注Youtube上的教程视频。 我查了好几次仍然无法找到任何问题。 错误是&#34; https://docs.angularjs.org/error/ng/areq?p0=SimpleController&p1=not%20a%20function,%20got%20undefined&#34; 请帮忙!

enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

您需要将视图分配给模板中的控制器,以便视图可以呈现范围数据

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

//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});

function MyCtrl($scope) {
            $scope.customers = [
                { name: 'Joe', city: 'Seattle'},
                { name: 'Jack', city: 'Dallas'},
                { name: 'Jason', city: 'Houston'}
            ];
        }
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" >
 <div class="container" ng-controller="MyCtrl">


        Name:
        <br/>
        <input type="text" ng-model="name" />{{name}}

        <br/>

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

    </div>
</div>

相关问题