I have a Simple page like
<body ng-app="myApp">
<div>
<h1>Courses</h1>
<ul class="nav">
<li><a href="#" ui-sref="route1">Route 1</a></li>
</ul>
</div>
<div ui-view>
</div>
<script src="Scripts/angular.js"></script>
<script src="Scripts/angular-ui-router.min.js"></script>
<script src="Scripts/app/app.js"></script>
And a app.js file like :
var myApp = angular.module('myApp', ['ui.router']);
var configFunction = function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('route1', {
url: "/courses",
templateUrl: "Scripts/app/views/Course/CourseList.html"
});
}
configFunction.$inject = ['$stateProvider', '$urlRouterProvider'];
myApp.config(configFunction);
and in my CourseList.html I have :
<script src="../../Controller/Course/CourseController.js"></script>
<div ng-controller="CourseController">
<h1>index</h1>
<table class="table table-striped">
<thead>
<tr>
<td>Id#</td>
<td>Name</td>
</tr>
</thead>
<tbody ng-repeat="course in courses |orderBy:'Id' ">
<tr>
<td>{{course.Id}}</td>
<td>{{course.Name}}</td>
</tr>
</tbody>
</table>
</div>
And my controller code:
angular.module('myApp').controller('CourseController', function ($scope, $http) {
$scope.course = {};
$http.get('/api/Course').success(function (data) {
$scope.courses = data;
});
});
Now when I click on Route 1 link I give this Error:
Error: [ng:areq] Argument 'CourseController' is not a function, got undefined
And when I comment controller refrence in CourseList.html and add it to index.html it's worke!!! Is there any way that I dont refrence all controllers in Index.html?