0

My spa showing below error...i hardly tried but am not getting solution...am new to angular...any help is appreciated...

Err::[$controller:ctrlreg] The controller with the name 'Mcontroller' is not registered.

index.html

<!DOCTYPE html>

<html ng-app="Dapp">
<head>
<meta charset="ISO-8859-1">
<script type="text/javascript" src="JS/angular.js"></script>
<script type="text/javascript" src="JS/angular-route.js"></script>
<title>DAPP</title>
</head>
<body ng-controller="Mcontroller">
<div class="ng-view"></div>

<script type="text/javascript" src="controllers/Mcontroller.js"></script>
<script type="text/javascript" src="controllers/Controller.js"></script>
<script type="text/javascript" src="controllers/Logincontrol.js"></script>

</body>
</html>

contrller.js

var app=angular.module('Dapp',['ngRoute']);
app.config(function($routeProvider) {

     $routeProvider
      .when('/', {templateUrl : 'Pages/login.html',controller  : 'Mcontroller' })
      .when('/login', {templateUrl : 'Pages/login.html',controller  : 'Logincontrol' })     
});

Mcontrol.js

app.controller('Mcontroller',function($scope){

        alert("HELLO");

});

Login.html

hello Buddy......
Michael
  • 556
  • 2
  • 8
  • Make sure your Mcontrol.js is properly linked or not, comment your routing code and simply leave alert. – shahid Jun 09 '18 at 19:20
  • You have to order the .js files. First your angular.module have to load. Seems your controller.js. then the rest. – Michael Jun 09 '18 at 19:24
  • Possible duplicate of [Can one AngularJS controller call another?](https://stackoverflow.com/questions/9293423/can-one-angularjs-controller-call-another) – Dhanunjay sharma Sep 17 '18 at 11:49

1 Answers1

1

Try to change the sequence to:

(Below sequence assumes that angular.module('Dapp',[]); is present in Controller.js file)

<script type="text/javascript" src="controllers/Controller.js"></script>
<script type="text/javascript" src="controllers/Mcontroller.js"></script>
<script type="text/javascript" src="controllers/Logincontrol.js"></script>

Make sure, angular.module('Dapp',[]); is included in <script> as the 1stjs` file in html page.

Shashank Vivek
  • 16,888
  • 8
  • 62
  • 104