I posted this question earlier and I honestly don't know what im doing wrong. I have being trying to solve this all day.
I'm going to post as much code as possible to give you guys as much details as possible.
The problem I'm having is that im trying to load a 3 child views after i login. after logged in i can see all 3 child views render in my html tool inspector but there partially render in the browser view. Upon research I think my problem is that I need to use a property called resolve to wait for all my templates and http to be finish before I transition to the next page after the login.
this is the login page
<ion-view view-title="login">
<ion-content class="padding has-header">
<div class="row">
<div class="col col-50 col-offset-25">
<div class="card">
<div class="item item-text-wrap">
<form ng-submit="processForm()">
<div class="list">
<label class="item item-input">
<input type="text" placeholder="First Name" ng-model="formData.AccessKey" required="true">
</label>
<label class="item item-input">
<input type="text" placeholder="Last Name" ng-model="formData.Password" required="true">
</label>
</div>
<button class="button button-full button-positive">
Sign me in
</button>
</form>
</div>
</div>
</div>
</div>
</ion-content>
this is my app js responsible for all the routing
.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();
}
});
})
.config(function($stateProvider, $urlRouterProvider, $ionicConfigProvider){
$ionicConfigProvider.views.transition('none')
$urlRouterProvider.otherwise('/');
$stateProvider
.state('login',{
url: '/',
templateUrl: 'templates/login.html',
controller:'loginController'
})
.state('main', {
url: '/main',
templateUrl: 'templates/main.html',
abstract: true
})
.state('main.panels', {
views: {
'ticketsPanel': {
templateUrl: 'templates/ticketsPanel.html'
},
'productsPanel': {
templateUrl: 'templates/productsPanel.html'
},
'categoriesPanel': {
templateUrl: 'templates/categoriesPanel.html',
controller: 'categoriesController'
}
}
})
})
this is my services
angular.module('starter.services', [])
.factory('Authentication', function($http, $q){
var deferred = $q.defer();
return {
login: function(formData) {
$http({
method : 'GET',
url : 'http://localhost:8888/employees/login',
params : formData
})
.success(function(respond){
deferred.resolve(respond);
})
},
getEmployee: function () {
return deferred.promise;
}
}
})
.factory('Categories', function($http){
//get the company id so i can get all the categories belong to that company
var CompanyId = JSON.parse(localStorage.getItem('employee'));
CompanyId = CompanyId[0].CompanyId;
return {
getCategories : function() {
$http({
method : 'GET',
url : 'http://localhost:8888/Categories/ajax_getCompaniesCategories',
params : {CompanyId: CompanyId}
})
.success(function(respond){
localStorage.setItem('categories', JSON.stringify(respond));
})
}
}
})
this is my controller
angular.module('starter.controllers', [])
.controller('loginController', function($scope, Authentication, $log, $state){
$scope.formData = {};
$scope.processForm = function(){
Authentication.login($scope.formData);
var promise = Authentication.getEmployee();
promise.then(function(respond){
localStorage.setItem('employee', JSON.stringify(respond));
$state.go('main.panels');
})
}
})
.controller('categoriesController', function($scope, Categories){
console.log('categories controller')
Categories.getCategories();
$scope.categories = JSON.parse(localStorage.getItem('categories'));
})
Sorry I usually try to only post a little bit of code but I'm desperate. Thanks in advance.