Issue
I'm new with angular JS MVC. First, I created on page ang separate angular JS file it was working fine then created another page added another controller in JS File and it started giving me error. then shifted my controllers to separate files. now on page is working and other is giving this error.
angular.js:15635 Error: [$controller:ctrlreg] The controller with the name 'ctrEmployee' is not registered.
I know there's already many questions related this error and tried all solutions but nothing worked. I'm exhausted and trying wasted almost a day on this error. Please don't mark my question duplicate may be I'm facing pother problem and have done any silly mistake. Here's my code:
App.js
var app;
(function () {
'use strict'; //Defines that JavaScript code should be executed in "strict mode"
app = angular.module("ngProject", ["ngRoute"]);
})();
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/Employee', {
templateUrl: 'Employee/Employee',
controller: 'Employee'
})
.when('/Company', {
templateUrl: '/Company/Company',
controller: 'Company'
}).otherwise({
templateUrl: "/Home/Index"
})
}]);
Company.js:
app.controller('ctrCompany', function ($scope, $http) { })
Employee.js:
app.controller('ctrEmployee', function ($scope, $http) { })
in _Layout.chtml head
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/angular.min.js"></script>
<script src="~/Scripts/angular-route.js"></script>
<script src="~/Scripts/AngularScripts/App.js"></script>
in Views
<script src="~/Scripts/AngularScripts/Controller/Company.js"></script>
<h3>Companies</h3>
<div ng-app="ngProject">
<div ng-controller="ctrCompany" ng-init="GetAllData()" class="divList"> </div>
</div>
<script src="~/Scripts/AngularScripts/Controller/Employee.js"></script>
<div ng-app="ngProject">
<div ng-controller="ctrEmployee" ng-init="GetAllData()" class="divList"> </div>
</div>
Please help me out as I'm familiar with angular but not in .net MVC.
Solution
The JavaScript controller had an error in code and that's why it was showing error on controller name but error was confusing, after reviewing my code found error and after correction it worked. Thank you everyone.
Answer: code had = instead of : in assigning value to parameter.
Answered By - angryBird
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.