Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
192
rated 0 times [  195] [ 3]  / answers: 1 / hits: 26882  / 9 Years ago, mon, october 12, 2015, 12:00:00

I have login page . When username and password is correct i want to redirect from login page to HomePage.html page.



Login.html



<ion-view view-title=Login name=login-view>
<ion-content class=padding>
<div class=list list-inset>
<label class=item item-input>
<input type=text placeholder=Username ng-model=data.username>
</label>
<label class=item item-input>
<input type=password placeholder=Password ng-model=data.password>
</label>
</div>
<button class=button button-block button-calm ng-click=login()>Login</button>
</ion-content>
</ion-view>


HomePage.html



<label id=test>test</label>


controller.js



.controller('LoginCtrl', function ($scope, LoginService, $ionicPopup, $state) {
$scope.data = {};

$scope.login = function () {
LoginService.loginUser($scope.data.username, $scope.data.password).success(function (data) {

$state.go('/HomePage'); // This is not working for me

}).error(function (data) {
var alertPopup = $ionicPopup.alert({
title: 'Login failed!',
template: 'Please check your credentials!'
});
});
}
})


Question:



When i try below code



$state.go('/HomePage');


this is not working for me.



I get below exception as below



Error: Could not resolve '/HomePage' from state 'login'


How can i reach homepage.html page from login page.



Any help will be appreciated.



Thanks.


More From » html

 Answers
30

use this :



$location.path('/HomePage');


Full code:



.controller('LoginCtrl', function ($scope, LoginService, $ionicPopup,$location) {
$scope.data = {};

$scope.login = function () {
LoginService.loginUser($scope.data.username, $scope.data.password).success(function (data) {

$location.path('/HomePage'); // working

}).error(function (data) {
var alertPopup = $ionicPopup.alert({
title: 'Login failed!',
template: 'Please check your credentials!'
});
});
}
})

[#64770] Thursday, October 8, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
longd

Total Points: 616
Total Questions: 110
Total Answers: 101

Location: Andorra
Member since Sat, May 27, 2023
1 Year ago
;