Issue
i’m using ui-router for routing but im getting an Error as controller is not Register
<title></title>
<script src="../../Scripts/angular.js"></script>
<script src="../../Scripts/angular-ui-router.js"></script>
<script src="Admin_MyApp.js"></script>
<script src="../EmployeePages/EmployeeScripting/Employee_MyApp.js">
<ul>
<li><a ui-sref="Contact()">Contact</a></li>
</ul>
admin_Myapp.js
var app = angular.module('Admin_MyApp', ['ui.router']);
app.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('Contact', {
url: 'contact',
templateUrl: '/Kpmg/AdminPages/EmployeeDetails/Feedback.html',
controller: 'abc'
})
})
contact.js
app.controller('abc', function ($scope) {
Solution
There are two issues in the code:
1- You need to add the contact.js to the html
2- Your controller must be defined before your state. So here is the correct order:
// define your module first
var app = angular.module('Admin_MyApp', ['ui.router']);
// define your controller on the module
app.controller('abc', function ($scope) {
// your controller
});
// define the state
app.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('Contact', {
url: 'contact',
templateUrl: '/Kpmg/AdminPages/EmployeeDetails/Feedback.html',
controller: 'abc'
})
})
Answered By – Arashsoft
Answer Checked By – Dawn Plyler (AngularFixing Volunteer)