Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: [ng:areq] customerController not a function got undefined

I am beginner to angularjs and I am writing a simple application to get started with it. I keep getting this error Error: [ng:areq] customerController not a function got undefined

I have tried to check whats wrong with my code and everything seems alright (at least for me). Kindly go through the code and help me out

Home.html

<html ng-app="customerApp">
<head>
<title> MyProject</title>
</head>

<body ng-controller="customerController">
<table border="2">
    <thead>
        <th ng-click="doSort('name')">Name</th>
        <th ng-click="doSort('city')">City</th>
    </thead>
    <tr ng-repeat="cust in customers | filter: customerFilter | orderBy:sortBy:reverse">
        <td>{{ cust.name }}</td>
        <td>{{ cust.city }}</td>
    </tr>
</table>
<br \>
<br \>
    Total customers: {{ customers.length }}

<script src="/scripts/angular.min.js"></script>
<script src="/app/app.js"></script>
<script src="/app/controllers/customerController.js"</script>
</body>
</html>

app.js

(function(){
    var app = angular.module('customerApp', []);
})();

customerController.js

(function (){

    var customerController = function ($scope){
        $scope.sortBy='name';
        $scope.reverse=false;

    $scope.customers= [{name:'Sachin',city:'Dharwad'},    {name:'Karan',city:'Hubli'},{name:'Shishir',city:'Mysore'}];
    $scope.doSort= function (propName){

        $scope.sortBy= propName;
        $scope.reverse= !$scope.reverse;
    };
};
    customerController.$inject = ['$scope'];
    angular.module('customerApp').controller('customerController',customerController    );
})();

PS: I have already referred this question

like image 498
Sachin Kariyattin Avatar asked Aug 08 '26 16:08

Sachin Kariyattin


1 Answers

You forgot to close the opening part of script tag . It is obvious in syntax highlighter in the question code

Change

<script src="/app/controllers/customerController.js"</script>

To

<script src="/app/controllers/customerController.js"></script>
like image 158
charlietfl Avatar answered Aug 11 '26 05:08

charlietfl



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!