Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I am getting ' Error: [$injector:modulerr] http://errors.angularjs.org/1.2.21/$injector/modulerr'

Tags:

angularjs

<html ng-app="demoapp">
<head>
    <script type="text/javascript" src="../angular.min.js"></script>
    <script type="text/javascript">
        var demoapp = angular.module('demoapp', []);

        demoapp.controller('SimpleController',function ($scope){
            $scope.customer = [
                {name: "Deepak" , city: "Bhubaneswar"},
                {name: "Sivaji" , city: "Banglore"}
            ];
            $scope.addCustomer = function($scope){
                $scope.customer.push({ name: $scope.newCustomer.name ,city: $scope.newCustomer.city});
            }
        }); 

        demoapp.config(function ($routeProvider){
            $routeProvider
                .when('/',{
                    controller: 'SimpleController',
                    templateUrl: 'Partials/view1.html'
                })
                .when('/view2',{
                    controller: 'SimpleController',
                    templateUrl: 'Partials/view2.html'
                })
                .otherwise({redirectTo: '/'});
        });

    </script>   
</head>
<body>
    <div ng-view=""></div>
</body>

Could any please suggest me what going wrong here?Why I am getting error. I am newbie to Angular please help. I think there is some issue with the config portion. But I am not able to debug it.

like image 731
user3427540 Avatar asked Mar 18 '23 18:03

user3427540


1 Answers

Add angular-route script

<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular-route.min.js"></script>

Add ngRoute as dependency

var demoapp = angular.module('demoapp', ["ngRoute"]);

You should define controller like this.

demoapp.controller('SimpleController',["$scope", function ($scope){
    $scope.customer = [
         {name: "Deepak" , city: "Bhubaneswar"},
         {name: "Sivaji" , city: "Banglore"}
    ];
        $scope.addCustomer = function($scope){
            $scope.customer.push({ name: $scope.newCustomer.name ,city: $scope.newCustomer.city});
        }
}]); 
like image 108
Darshan P Avatar answered Apr 25 '23 07:04

Darshan P