错误:[ng:areq]参数'simpleController'不是一个函数,未定义 [英] Error: [ng:areq] Argument 'simpleController' is not a function, got undefined

查看:92
本文介绍了错误:[ng:areq]参数'simpleController'不是一个函数,未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里做错什么,我是新手,它显示了上面的错误,这是我的代码

What am i doing wrong here, I am new to angular, its showing the error above, here is my code

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.js"></script>
        <script>
            function simpleController($scope){
                $scope.customers=[
                    {name:'Alphy Poxy',city:'Mbita'},
                    {name:'Kibaki Watson',city:'Kikuyu'},
                    {name:'John Legend',city:'Lake'}, 
                    {name:'Sony',city:'HB'}
                ];
            }
        </script>

    </head>
    <body>
        <div class="container-fluid" ng-controller="simpleController">
            Name: <input type="text" ng-model="name"/>
            <ul>
                <li ng-repeat="coders in customers | filter:name | orderBy:'name'">{{coders.name}}-{{coders.city}}</li>
            </ul>
        </div>
    </body>   

推荐答案

您尚未正确创建控制器.请查看以下代码段.

You haven't created properly your controller. Please see the following snippet.

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

myApp.controller('simpleController', ['$scope', function($scope) {
    $scope.customers=[
                    {name:'Alphy Poxy',city:'Mbita'},
                    {name:'Kibaki Watson',city:'Kikuyu'},
                    {name:'John Legend',city:'Lake'}, 
                    {name:'Sony',city:'HB'}
                ];    
}]);

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div class="container-fluid" ng-app="myApp" ng-controller="simpleController">
    Name: <input type="text" ng-model="name"/>
    <ul>
        <li ng-repeat="coders in customers | filter:name | orderBy:'name'">{{coders.name}}-{{coders.city}}</li>
    </ul>
</div>

这篇关于错误:[ng:areq]参数'simpleController'不是一个函数,未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆