登录成功后跳转到UI-路由
Redirect to UI-Route after Login Successfully
如何在登录成功后重定向到主页,
我正在使用 UI-路由器,下面是我的 ui-路由器代码。
var myrouting=angular.module('routingDemoApp', ['ui.router'])
myrouting.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise("", "/index")
$stateProvider
.state('index', {
url: "/index",
templateUrl: "../Views/home.html"
})
.state('contactus', {
url: "/contactus",
templateUrl: "../Views/contactus.html",
})
.state('home', {
url: "/home",
templateUrl: "../Views/home.html",
})
.state('myModal', {
url: "/myModal",
templateUrl: "../Views/SignInPage.html",
})
}]);
我有一个按钮元素调用 ng-click='login function' 来验证用户名和密码。一旦凭据有效,我想将页面重定向到 "Home.html"
下面函数登录成功后如何调用ui-route?
var mymodule2 = angular.module('module2', []);
mymodule2.controller('controller2', function ($scope) {
$scope.loginFunction = function () {
alert("Login");
if ($scope.username == 'abcd' && $scope.password == 'hello123') {
console.log('Login sucessfull');
***// Redirect to Home Page.***
}
}
});
您可以像这样使用 $state.go("home");
,其中 "home" 是您想去的州名称:
var mymodule2 = angular.module('module2', []);
mymodule2.controller('controller2', function ($scope, $state) {
$scope.loginFunction = function () {
alert("Login");
if ($scope.username == 'abcd' && $scope.password == 'hello123') {
console.log('Login sucessfull');
$state.go("home");
}
}
});
使用`$state.go("home");
var mymodule2 = angular.module('module2', []);
mymodule2.controller('controller2', function ($scope) {
$scope.loginFunction = function () {
alert("Login");
if ($scope.username == 'abcd' && $scope.password == 'hello123') {
console.log('Login sucessfull');
// add $state.go here
$state.go("home);
}
}
});
如何在登录成功后重定向到主页,
我正在使用 UI-路由器,下面是我的 ui-路由器代码。
var myrouting=angular.module('routingDemoApp', ['ui.router'])
myrouting.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise("", "/index")
$stateProvider
.state('index', {
url: "/index",
templateUrl: "../Views/home.html"
})
.state('contactus', {
url: "/contactus",
templateUrl: "../Views/contactus.html",
})
.state('home', {
url: "/home",
templateUrl: "../Views/home.html",
})
.state('myModal', {
url: "/myModal",
templateUrl: "../Views/SignInPage.html",
})
}]);
我有一个按钮元素调用 ng-click='login function' 来验证用户名和密码。一旦凭据有效,我想将页面重定向到 "Home.html"
下面函数登录成功后如何调用ui-route?
var mymodule2 = angular.module('module2', []);
mymodule2.controller('controller2', function ($scope) {
$scope.loginFunction = function () {
alert("Login");
if ($scope.username == 'abcd' && $scope.password == 'hello123') {
console.log('Login sucessfull');
***// Redirect to Home Page.***
}
}
});
您可以像这样使用 $state.go("home");
,其中 "home" 是您想去的州名称:
var mymodule2 = angular.module('module2', []);
mymodule2.controller('controller2', function ($scope, $state) {
$scope.loginFunction = function () {
alert("Login");
if ($scope.username == 'abcd' && $scope.password == 'hello123') {
console.log('Login sucessfull');
$state.go("home");
}
}
});
使用`$state.go("home");
var mymodule2 = angular.module('module2', []);
mymodule2.controller('controller2', function ($scope) {
$scope.loginFunction = function () {
alert("Login");
if ($scope.username == 'abcd' && $scope.password == 'hello123') {
console.log('Login sucessfull');
// add $state.go here
$state.go("home);
}
}
});