Not able to display home page from login

Hi,
Requirement:is when i click logon button in login page,it should display home page but i am not able display home page.

code:
var app=angular.module(‘todo’, [‘ionic’, ‘ui.router’])

app.config(function($stateProvider, $urlRouterProvider) {
// $urlRouterProvider.otherwise(’/’);

$stateProvider.state(‘main’, {
url: ‘/’,
abstract: true,
templateUrl: ‘template/main.html’
})
})

Inside controller and login function below code written:

$state.go(‘main’);

$state passing from controller.

Please let me know the what could be the wrong in my code.

regards,
suresh

on click login button pass an id in localStorage or database and check that condition in MainController
if(id.exists)
{
$state.go(‘main’)

}
else{

$state.go(‘login’);

}

Hi,

I don’t have problem with login validation but i am not able to display or redirect to home page with calling $state.go(‘main’) function. apart from calling $state.go(‘main’) any thing i missed for redirecting to home page.

regards,
suresh

now i can see your code you did not defined your controller in

$stateProvider.state(‘main’, {
url:’/’,
controller :‘MainCtrl’,
templateUrl:‘template/main.html’

})

Hi,
I added above controller code but still not able to redirect to home page.
Any thing extra code i need to specify apart from this.

regards,
suresh

any javascript error ?

have you defined the template and controller files ?
have you included the controller js files in index.html ?

could you show your app.js and controllers.js files ?
ideally the whole project on github, then we can help

I saw in your original file you had the abstract:true, which is not needed
not sure if you have removed that after adding what nitishrajput01 said

I am not getting any java script error and it resides in same login page with new data.
I added controller code also in app.js and mentioned below.

var app=angular.module(‘todo’, [‘ionic’, ‘ui.router’])

app.config(function($stateProvider, $urlRouterProvider) {
// $urlRouterProvider.otherwise(’/’);

$stateProvider.state(‘main’, {
url:’/’,
controller :‘homeCtrl’,//this is specified in main.html and tried with TodoCtrl also
templateUrl:‘template/main.html’

})
})

.controller(‘TodoCtrl’, function($scope,$http,$state) {
$scope.login = function(data) {
prompt(“clicked button”+data.userId+data.password);

$http.get(’/services/rest/specialities’

).then(function(resp) {

// prompt("clicked button"+angular.toJson(resp, null));
$scope.status = angular.toJson(resp, null);

$state.go(‘main’);

}, function(err) {
console.error(‘ERR’, err);
prompt(“error”+err);
// err.status will contain the status code
})

};
});

@sureshtellakula

$state provider is used to defined your templates with controller and provides the routing
if you are using controller in your main.html than you have to route the state from current to another one

even i tried with defining empty homeCtrl but still not working. I am not understanding what could be the wrong.
In this case do i need to specify same controller which specified in login page or home controller which specified in main.html. I tired with both but it is not redirecting.

regards,
suresh

Here is the example

https://devdactic.com/simple-login-example-with-ionic-and-angularjs/

I followed from this example only.

Do i need to specify like below for both login and main:

$stateProvider
.state(‘login’, {
url: ‘/login’,
templateUrl: ‘templates/login.html’,
controller: ‘LoginCtrl’
})
.state(‘main’, {
url: ‘/’,
abstract: true,
templateUrl: ‘templates/main.html’
})

As per my understanding only main i need to specify for my requirement.

yes you have to specify

Hi,

Why do i need to specify both. I specified login screen code in index.html
index.html body code given below:

<ion-pane>
  <ion-header-bar class="bar-stable">
    <h1 class="title">sales Tracer</h1>
  </ion-header-bar>
  
  <ion-content>
  <div class="list list-inset">
      <label class="item item-input">
          <input type="text" placeholder="UserId" ng-model="data.userId">
      </label>
      <label class="item item-input">
          <input type="password" placeholder="password" ng-model="data.password">
      </label>
  </div>
      
  <button class="button button-block button-positive" ng-click="login(data)">Login</button>

when i click Login button from it should go to home page.

and also i executed above login example also. It is displaying blank page instead of Login page.

regards,
suresh

suggest you to read the sample templates to get some concepts about ui-router and code folder structure

run the following command to generate sidemenu and tabs template

ionic start sampleSideMenu sidemenu
ionic start sampleSideMenu tabs

it should help you to understand a bit how to organize pages, states, view and controller