admin管理员组文章数量:1333451
I have following code.All I am trying is to make a simple login and dashboard app. after successful login the user can see dashboard for that I have two routes login and dashboard initially login route is default once login is successful then I want to route to dashboard route and the respective template and controller should get loaded but somehow that does not work. I need help to figure out what is wrong
index.html
<html lang="en" ng-app="salesApp">
<body ng-controller="loginController">
<form name="loginForm">
<!--login form-->
</form>
<script src="./js/lib/angular.min.js"></script>
<script src="./js/lib/angular-route.min.js"></script>
<script src="./js/app/salesApp.js"></script>
<script src="./js/controller/loginController.js"></script>
<script src="./js/services/municationService.js"></script>
</body>
</html>
loginController.js
app.controller('loginController', function($scope, $http, municationService, $location){
$scope.isLoginFailed = false;
$scope.login= function(){
$http.get("http://localhost:8080/login?username=" + $scope.user.username + "&password=" + $scope.user.password)
.success(function(response){
if(response.sessionId && response.loginSucceeded){
$location.path("/login");
}else{
$scope.isLoginFailed = true;
}
});
}
});
salesApp.js
var app = angular.module("salesApp", ['ngRoute']);
app.config(['$routeProvider',
function($routeProvider) {
debugger;
$routeProvider.
when('/login', {
templateUrl: '../../login.html',
controller: 'loginController'
}).
when('/dashboard', {
templateUrl: '../../dashboard.html',
controller: 'dashBoardController'
}).
otherwise({
redirectTo: '/login'
});
}]);
app.controller('dashBoardController', function($scope, $http, municationService){
$scope.sessionData = municationService.getSessionData();
$scope.isValidSession - $scope.sessionData.sessionId !== null ? true : false;
$scope.isValidSession = $scope.isValidSession && $scope.sessionData.loginSucceeded;
});
dashboard.html
<html ng-app="salesApp">
<head>
</head>
<div ng-view ng-controller="dashBoardController">
<h1>
demo
</h1>
</body>
but neither login nor dashboard route gets fired, Can any one help me to find out what wrong am I doing
I have following code.All I am trying is to make a simple login and dashboard app. after successful login the user can see dashboard for that I have two routes login and dashboard initially login route is default once login is successful then I want to route to dashboard route and the respective template and controller should get loaded but somehow that does not work. I need help to figure out what is wrong
index.html
<html lang="en" ng-app="salesApp">
<body ng-controller="loginController">
<form name="loginForm">
<!--login form-->
</form>
<script src="./js/lib/angular.min.js"></script>
<script src="./js/lib/angular-route.min.js"></script>
<script src="./js/app/salesApp.js"></script>
<script src="./js/controller/loginController.js"></script>
<script src="./js/services/municationService.js"></script>
</body>
</html>
loginController.js
app.controller('loginController', function($scope, $http, municationService, $location){
$scope.isLoginFailed = false;
$scope.login= function(){
$http.get("http://localhost:8080/login?username=" + $scope.user.username + "&password=" + $scope.user.password)
.success(function(response){
if(response.sessionId && response.loginSucceeded){
$location.path("/login");
}else{
$scope.isLoginFailed = true;
}
});
}
});
salesApp.js
var app = angular.module("salesApp", ['ngRoute']);
app.config(['$routeProvider',
function($routeProvider) {
debugger;
$routeProvider.
when('/login', {
templateUrl: '../../login.html',
controller: 'loginController'
}).
when('/dashboard', {
templateUrl: '../../dashboard.html',
controller: 'dashBoardController'
}).
otherwise({
redirectTo: '/login'
});
}]);
app.controller('dashBoardController', function($scope, $http, municationService){
$scope.sessionData = municationService.getSessionData();
$scope.isValidSession - $scope.sessionData.sessionId !== null ? true : false;
$scope.isValidSession = $scope.isValidSession && $scope.sessionData.loginSucceeded;
});
dashboard.html
<html ng-app="salesApp">
<head>
</head>
<div ng-view ng-controller="dashBoardController">
<h1>
demo
</h1>
</body>
but neither login nor dashboard route gets fired, Can any one help me to find out what wrong am I doing
Share Improve this question edited Mar 22, 2015 at 18:06 Radim Köhler 124k48 gold badges242 silver badges340 bronze badges asked Mar 22, 2015 at 17:41 nikhil mehtanikhil mehta 1,03216 silver badges32 bronze badges1 Answer
Reset to default 6You don't have to repeat angular ng-app
and ng-view ng-controller="dashBoardController"
directives in partial templates. Change dashboard.html
like this:
<h1>demo</h1>
However in index.html
you have to put ngView
somewhere. It will be filled with loaded templates:
<div ng-view></div>
Check the demo with fixed code:
Demo: http://plnkr.co/edit/Is3oXmkcRvDYkiAuvnCF?p=preview
本文标签: javascriptangular js route not workingStack Overflow
版权声明:本文标题:javascript - angular js route not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742353525a2458962.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论