I am using cordova to develop mobile app with ionic framework. I am using $http.post method to send request & receive response in json format. On successful activity i want to navigate to next page. My code is this:
.controller('Intro', function($scope, $http, $ionicSlideBoxDelegate, $state, $timeout, $ionicLoading, $ionicPopup) {
$scope.login = function(user) {
var userName = user.username;
var passWord = user.password;
$ionicLoading.show({
template: 'Logging in...'
});
$http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
$http.post(base_url + "get/memberLogin.php?username=" + userName + "&password=" + passWord + "&tempKey=XHJJUQWERgfrbbbbokaw1222344", {}).success(function(data, status, headers, config) {
if (data.alert === 'SUCCESS') {
$timeout(function() {
$ionicLoading.show({
template: 'Success'
});
}, 1600);
var UserData = data.userdata;
var Username = UserData.personal_information.first_name + " " + UserData.personal_information.last_name;
var Email = UserData.username;
var LastLogin = new Date(UserData.last_visited * 1000);
$scope.users = [{
username: Username,
email: Email,
location: true,
id: null,
avatar: 'img/men.jpg',
enabled: 'true',
lastLogin: LastLogin
}];
$timeout(function() { // it navigates you to next slide to be shown
$ionicLoading.hide();
$state.href('templates/dashboard.html'); // getting problem here.
}, 2000);
}
});
Problem is i tried $state.href('templates/dashboard.html');
but it is not navigating to. even i tried $state.go('templates/dashboard.html');
& $state.go('^.dashboard');
as to go with absolute one but still it doesnt work. Which is the working one??
I am not getting any error on console too... where is the problem?
Updated route configuration
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('router', {
url: "/route",
abstract: true,
templateUrl: "templates/side-menu-left.html"
})
.state('router.dashboard', {
url: "/dashboard",
abstract: true,
views: {
'menuContent' :{
templateUrl: "templates/dashboard.html"
}
}
})
.state('router.dashboard.home', {
url: "/home",
views: {
'home-tab' :{
templateUrl: "templates/home.html"
}
}
})
....so on.....
Navigation is driven by routes.
For e.g., in your case you can configure routes like this :
orderStatusApp.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('Dashboard', {
url: "/Dashboard",
templateUrl: "templates/dashboard.html"
});
});
Then you can use either $state or $location. For e.g., in this case you can use $location like this :
$location.path('Dashboard');
or you may also try
$state.transitionTo('Dashboard');
For more details on angular route, check this out, for an alternative and more popular routing plugin, check this.