我有我正在处理的这个 angularJS 应用程序。我有一个运行良好的登录页面;但是,无法转换到菜单页面。视图没有按预期被替换。我在这里错过了什么或做错了什么?以下是我的应用程序中的一些部分代码:
var Admin = angular.module('Admin', ['ui.router', 'Admin.Services', 'angularUtils.directives.dirPagination']);
Admin.controller('LoginController', LoginController);
Admin.controller('AuthenticateHeader', AuthenticateHeader);
Admin.factory('AuthHttpResponseInterceptor', AuthHttpResponseInterceptor);
// Admin.factory('AuthHttpResponseInterceptor', AuthHttpResponseInterceptor);
Admin.config(['$stateProvider', '$httpProvider', '$locationProvider', '$urlRouterProvider',
function ($stateProvider, $httpProvider, $locationProvider, $urlRouterProvider) {
$httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest'; //This is important for angiforgen
$locationProvider.hashPrefix('!').html5Mode(true);
$urlRouterProvider.otherwise('/Login');
$urlRouterProvider.when("/", "/Login");
$stateProvider
.state('Admin', {
abstract: true,
views: {
'header': {
templateUrl: '/Navigation/UnAuthenticateHeader'
},
'content': {
templateUrl: '/Navigation/Content'
}
}
})
.state('Admin.login', {
url: "/Login",
views: {
"content@": {
templateUrl: '/Account/Login',
controller: 'LoginController'//function ($scope,$stateParams) {
// }
}
}
})
.state('menu', {
// url: '/Menu',
abstract : true,
views: {
templateUrl: '/Landing/Home',
controller: function ($scope) {
$scope.message = 'menu controller';
}
},
data: {
proxy: 'Home'
},
})
.state('menu.home',
{
url: '/Home',
views: {
'nav@menu': {
templateUrl: '/Navigation/AuthHeader',
controller: function ($scope) {
$scope.message = 'single message';
}
},
'content@menu': {
templateUrl: '/Landing/Index',
controller: function ($scope) {
$scope.message = 'Content menu';
}
}
}
})
// $httpProvider.interceptors.push('AuthHttpResponseInterceptor');
}]);
// 索引页
<!DOCTYPE html>
<html lang="en" ng-app="Admin">
<head>
<title>Admin Decision Support Engine</title>
<base href="/" />
@Styles.Render("~/Content/css")
</head>
<body>
<table>
<tr><td style="height:10%">
<div ui-view="header"></div>
</td></tr>
<tr><td style="height:90%">
<div ui-view="content"></div>
</td></tr>
</table>
<footer id="footer">
<span class="text-muted pull-left" style="margin-left: .5% !important;">Admin</span>
<span class="text-muted pull-right" style="margin-right: 3% !important;">Admin </span>
</footer>
@Scripts.Render("~/Bundles/myScripts")
</body>
</html>
//首页登陆页面
<div ui-view="nav" ng-cloak>
</div>
<section class="mainContent">
<section class="Display">
<div ui-view="content" ng-cloak>
</div>
</section>
</section>
//部分控制器 - 将用户重定向到菜单主页
if (!LoginInfo.Org) {
var result = LoginUser(LoginFactory, ToastMessageFactory, LoginInfo);
result.then(function (result) {
if (result.success) {
saveLoginInformation(result.data[0]);
//todo redirect the user
// $state.go('Admin.home');
$state.go('menu.home');
}
});
//未认证的标头
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Admin Authenticate Decision Support Engine</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav pull-right">
<li>
<a id="Logout" role="button"><span class="glyphicon glyphicon-log-in">{{username}}</span></a>
</li>
</ul>
</div>
</div>
//索引页只有以下消息
{{ message }}