I'm trying to code a spring boot application based in Angularjs. I have a project structure as follows:
The controller calls the index.html perfectly:
the app.js:
var app = angular.module('app', ['ngRoute','ngResource']);
app.config(function($routeProvider){
$routeProvider
.when('/users',{
templateUrl: 'views/users.html',
controller: 'usersController'
})
.when('/roles',{
templateUrl: 'views/roles.html',
controller: 'rolesController'
})
.otherwise(
{ redirectTo: '/'}
);
});
I get the first page when running the app but when I click on the links users and roles, nothing happens.
UPDATED: the index.html is:
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Spring boot and Angularjs Tutorial</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/css/app.css">
</head>
<body>
<h2>Administrator Panel</h2>
<div class="home-section">
<ul class="menu-list">
<li><a href="#/users">Users</a></li>
<li><a href="#/roles">Roles</a></li>
</ul>
</div>
<div ng-view></div>
<script src="/lib/angular.js"></script>
<script src="/lib/angular-resource.js"></script>
<script src="/lib/angular-route.js"></script>
<script src="/js/app.js"></script>
<script src="/js/controller.js"></script>
<link href="/css/bootstrap.css" rel="stylesheet" />
</body>
</html>
How can I fix this issue.
[1]:
For link in AngularJS you should use ng-href
directive: https://docs.angularjs.org/api/ng/directive/ngHref
Ex.
<a ng-href="#/users">Users</a>
<ul class="menu-list">
<li><a ui-sref="users">Users</a></li>
<li><a ui-sref="roles">Roles</a></li>
</ul>
Try this one. You can use ui-sref
for navigation from html page
您是否在模板开头声明了ng-app =“ app” ?
Here is how i fixed this issue:
<div class="list-group">
<a href="#home" class="list-group-item"
ng-class="{active: currentNavLink == '/home'}"> <i
class="fa fa-home fa-lg"></i> Home
</a> <a href="#contacts" class="list-group-item"
ng-class="{active: currentNavLink == '/contacts'}"> <i
class="fa fa-user fa-lg"></i> Contacts
</a> <a href="#todos" class="list-group-item"
ng-class="{active: currentNavLink == '/todos'}"> <i
class="fa fa-indent fa-lg"></i> ToDos
</a>
</div>
where in the app.js:
myApp.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.when('', '/home');
$urlRouterProvider.otherwise('/home');
/*
$urlRouterProvider.rule(function($injector, $location) {
return '/home';
});
*/
$stateProvider
.state('home', {
url: '/home',
templateUrl: 'templates/home.html',
controller: 'HomeController'
})
.state('contacts', {
url: '/contacts',
templateUrl: 'templates/contacts.html',
controller: 'ContactController'
})
.state('todos', {
url: '/todos',
templateUrl: 'templates/todos.html',
controller: 'TodoController'
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.