// Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// ‘starter’ is the name of this angular module example (also set in a attribute in index.html)
// the 2nd parameter is an array of ‘requires’
angular.module(‘fffff’, [‘ionic’, ‘chart.js’, ‘ui.router’])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
//Multiple Controllers Approach Start
.config(function ($stateProvider, $urlRouterProvider) {
// Ionic uses AngularUI Router which uses the concept of states
// Learn more here: https://github.com/angular-ui/ui-router
// Set up the various states which the app can be in.
// Each state's controller can be found in controllers.js
//alert("stateProvider"+$stateProvider.state);
//LoginCtrl HomeCtrl
$stateProvider
.state('login', {
url: '/',
templateUrl: 'index.html',
controller: 'loginCtrl'
})
//<p>Hello, world!</p>
$stateProvider
.state('fhcentral', {
url: '/fhcentral',
templateUrl: 'fh_central.html',
controller: 'fhCtrl'
})
// if none of the above states are matched, use this as the fallback
//$urlRouterProvider.otherwise('/employees');
$urlRouterProvider.otherwise('/');
})
//Multiple Controllers Approach End
.controller(‘loginCtrl’, function($scope, $location, $ionicSideMenuDelegate, $http, $stateParams, $state) {
$scope.errMsg = “”;
$scope.response = “”;
$scope.login = function () {
if(!$scope.uname) {
$scope.errMsg = “Please enter your username !”;
$state.go(‘login’);
}
if(!$scope.pwd) {
$scope.errMsg = "Please enter your password !";
$state.go('login');
}
if(!$scope.uname && !$scope.pwd) {
$scope.errMsg = "Please enter your username and password !";
$state.go('login');
}
// Here Need the Validation
if($scope.uname && $scope.pwd)
{
$http.get('http://10.10.10.227:8080/DataAnalysisPOC/Login/userLogin', {
params: {
userId: '123456',
authCode: "123456",
emailId: $scope.uname,
password: $scope.pwd
}
})
.success(function (data,status) {
//User does not exist
var response = angular.toJson(data);
var response = JSON.parse(response);
//alert(response.LoginDetail[0].message);
if(response.LoginDetail[0].message == "User does not exist") {
$scope.errMsg = "User does not exist !";
$state.go('login');
}
if(response.LoginDetail[0].message == "Password Incorrect") {
$scope.errMsg = "Password Incorrect !";
$state.go('login');
}
if(response.LoginDetail[0].message == "Password Matched") {
//$scope.errMsg = "Password Matched !";
window.localStorage.clear();
window.localStorage['username'] = $scope.uname;
window.localStorage['pwd'] = $scope.pwd;
window.localStorage['pgmId'] = response.LoginDetail[0].pgmId;
window.localStorage['email'] = response.LoginDetail[0].email;
window.localStorage['userId'] = response.LoginDetail[0].userId;
window.localStorage['roleCode'] = response.LoginDetail[0].roleCode;
window.localStorage['roleId'] = response.LoginDetail[0].roleId;
window.localStorage['accId'] = response.LoginDetail[0].accId;
window.localStorage['userType'] = response.LoginDetail[0].userType;
//$scope.succMsg == "Welcome to Home Page";
alert("Hi");
$state.go('fhcentral');
//$location.path("/fhcentral");
//$location.path("/fhcentral");
//$location.transitionTo('/fhcentral');
}
//User does not exist
//return false;
//var message = response.LoginDetail[0].message;
});
}
}
})
.controller(‘fhCtrl’, function($scope, $ionicSideMenuDelegate, $http, $stateParams, $state) {
alert(“Hi”);
})
In the above app.js code … the $state.go(‘fhcentral’); piece of code is not working … I am not able to redirect to the relevant fh_central.html page successfully …
May I know what is the reason ?