Reputation: 79
I have a simple angular app and two links which I want angular to change the URL for me and show the right view for each link in the same single page application. But when I add controllers' module in main module - it doesn't work!
app.js
'use strict';
var app = angular.module('app', ['ngRoute','ngResource','ngSanitize','ui.select','appControllers'])
.config(['$routeProvider',function($routeProvider){
$routeProvider
.when('/roles',{
templateUrl: '/views/roles.html',
controller: 'rolesController'
})
.otherwise(
{ redirectTo: '/views/index.html'}
);
}]);
index.html
<!DOCTYPE html>
<html ng-app="app">
<head>
<title>Spring boot and Angularjs Tutorial</title>
<link rel="stylesheet" href="/css/app.css">
<script src="/js/app.js"></script>
<script src="/js/controllers.js"></script>
</head>
<body>
<h2>Administrator Panel</h2>
<div class="home-section">
<ul class="menu-list">
<li><a href="#/report">Report</a></li>
<li><a href="#/roles">Roles</a></li>
</ul>
</div>
<div ng-view></div>
</body>
</html>
controllers.js
'use strict';
var appControllers = angular.module('appControllers');
appControllers.controller('rolesController', ['$scope', function($scope) {
$scope.headingTitle = "Roles List";
}]);
When there is no 'appControllers' in app.js views is working, but controllers don't.
var app = angular.module('app', ['ngRoute','ngResource','ngSanitize','ui.select'])
With - nothing works. What should I do?
Upvotes: 2
Views: 69
Reputation: 8598
Change
var appControllers = angular.module('appControllers');
to
var appControllers = angular.module('appControllers',[]);
Your code is trying to fetch an existing module that doesn't exist.
Beware that using angular.module('myModule', []) will create the module myModule and overwrite any existing module named myModule. Use angular.module('myModule') to retrieve an existing module.
Upvotes: 3