Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: [ng:areq] Argument 'simpleController' is not a function, got undefined

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>   
like image 737
alphy Avatar asked Jun 07 '26 14:06

alphy


2 Answers

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>
like image 91
Christos Avatar answered Jun 10 '26 03:06

Christos


Or at least you need to pub ng-app directive in parent html tag please see demo below

 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 src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app>
  <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>
</div>
like image 26
sylwester Avatar answered Jun 10 '26 04:06

sylwester



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!