var app = angular.module("myApp", ['ui.router']).
config(['$stateProvider', function ($stateProvider) {
$stateProvider.state('login', {
url: '/login',
templateUrl: '/templates/LoginPage.html',
controller: 'loginController'
});
}]);
app.controller("homePageController", function ($scope, $state) {
var self = this;
$scope.isLoginError = false;
$scope.loginSuccess = false;
$scope.validateCredentials = function () {
if ($scope.userName != '' && $scope.passWord != '') {
$scope.loginSuccess = true;
$scope.isLoginError = false;
// $location.url('/login');
$state.go('login');
}
else {
$scope.isLoginError = true;
}
}
});
//这是我的angularJS代码,当状态发生变化时http://localhost:44212/templates/homePage.html#!/login我得到了!在网址中,它没有导航到其他视图。
Can anyone please help me out to solve this problem.
Thanks in advance.
答案 0 :(得分:0)
你有任何错误吗?根据您在此提供的内容,它应该可行。我创建了一个工作plnk供您比较代码。
http://plnkr.co/edit/5AuB8qAtuttP4p6m3ZIY?p=preview
我添加的唯一真实内容是:
$stateProvider.state('home', {
url: '/',
templateUrl: 'HomePage.html',
controller: 'homePageController'
});
$urlRouterProvider.otherwise('/');
和
app.controller("loginController", function($scope, $state) {
console.log('loginController loaded');
});