I was watching this video of andew joslin https://www.youtube.com/watch?v=ZjPRj2Vp74U and practicing along and everything works fine with ionic
but when I tried doing the same project with ionic-material , $q didn't seem to change the list property of people
notice : i changed people to lawers :)
here is the app controller which is used for the menu :
=====================================
angular.module('starter.controllers', [])
angular.module('starter.controllers', [])
.controller('AppCtrl', function($scope, $ionicModal, $ionicPopover, $timeout) {
// Form data for the login modal
$scope.loginData = {};
$scope.isExpanded = false;
$scope.hasHeaderFabLeft = false;
$scope.hasHeaderFabRight = false;
var navIcons = document.getElementsByClassName('ion-navicon');
for (var i = 0; i < navIcons.length; i++) {
navIcons.addEventListener('click', function() {
this.classList.toggle('active');
});
}
////////////////////////////////////////
// Layout Methods
////////////////////////////////////////
$scope.hideNavBar = function() {
document.getElementsByTagName('ion-nav-bar')[0].style.display = 'none';
};
$scope.showNavBar = function() {
document.getElementsByTagName('ion-nav-bar')[0].style.display = 'block';
};
$scope.noHeader = function() {
var content = document.getElementsByTagName('ion-content');
for (var i = 0; i < content.length; i++) {
if (content[i].classList.contains('has-header')) {
content[i].classList.toggle('has-header');
}
}
};
$scope.setExpanded = function(bool) {
$scope.isExpanded = bool;
};
$scope.setHeaderFab = function(location) {
var hasHeaderFabLeft = false;
var hasHeaderFabRight = false;
switch (location) {
case 'left':
hasHeaderFabLeft = true;
break;
case 'right':
hasHeaderFabRight = true;
break;
}
$scope.hasHeaderFabLeft = hasHeaderFabLeft;
$scope.hasHeaderFabRight = hasHeaderFabRight;
};
$scope.hasHeader = function() {
var content = document.getElementsByTagName('ion-content');
for (var i = 0; i < content.length; i++) {
if (!content[i].classList.contains('has-header')) {
content[i].classList.toggle('has-header');
}
}
};
$scope.hideHeader = function() {
$scope.hideNavBar();
$scope.noHeader();
};
$scope.showHeader = function() {
$scope.showNavBar();
$scope.hasHeader();
};
$scope.clearFabs = function() {
var fabs = document.getElementsByClassName('button-fab');
if (fabs.length && fabs.length > 1) {
fabs[0].remove();
}
};
})
===============================
and here is the config of the app.js
================================
.config(function($stateProvider, $urlRouterProvider, $ionicConfigProvider) {
// Turn off caching for demo simplicity's sake
$ionicConfigProvider.views.maxCache(0);
/*
// Turn off back button text
$ionicConfigProvider.backButton.previousTitleText(false);
*/
$stateProvider.state('app', {
url: '/app',
abstract: true,
templateUrl: 'templates/menu.html',
controller: 'AppCtrl'
})
.state('app.lawers', {
url: '/lawers',
views: {
'menuContent': {
templateUrl: 'templates/lawers.html',
controller: 'lawersCtrl'
},
'fabContent': {
template: '<button id="fab-lawers" class="button button-fab button-fab-top-left expanded button-energized-900 spin"><i class="icon ion-chatbubbles"></i></button>',
controller: function ($timeout) {
$timeout(function () {
document.getElementById('fab-lawers').classList.toggle('on');
}, 900);
}
}
}
})
.state('app.login', {
url: '/login',
views: {
'menuContent': {
templateUrl: 'templates/login.html',
controller: 'LoginCtrl'
},
'fabContent': {
template: ''
}
}
})
.state('app.profile', {
url: '/profile',
views: {
'menuContent': {
templateUrl: 'templates/profile.html',
controller: 'ProfileCtrl'
},
'fabContent': {
template: '<button id="fab-profile" class="button button-fab button-fab-bottom-right button-energized-900"><i class="icon ion-plus"></i></button>',
controller: function ($timeout) {
/*$timeout(function () {
document.getElementById('fab-profile').classList.toggle('on');
}, 800);*/
}
}
}
})
;
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/app/login');
});
==============================================
here is my LawersController
==============================================
.controller('lawersCtrl', function($scope, $stateParams, $timeout, ionicMaterialInk, ionicMaterialMotion , Lawers ) {
// Set Header
$scope.$parent.showHeader();
$scope.$parent.clearFabs();
$scope.$parent.setHeaderFab('left');
$scope.lawers = Lawers.list;
console.log($scope.lawers);
// Delay expansion
$timeout(function() {
$scope.isExpanded = true;
$scope.$parent.setExpanded(true);
}, 300);
// Set Motion
ionicMaterialMotion.fadeSlideInRight();
// Set Ink
ionicMaterialInk.displayEffect();
})
======================================
the console log prints out an empty array !!!!!!
finally here is the service
=====================================
angular.module('starter.services', []) .factory('Lawers', function($http , $q){
var lawers = {};
lawers.list = [];
lawers.add = function(){
return $http.get('http://api.randomuser.me')
.then(function(res){
lawers.list.push(res.data.results[0].user);
});
};
lawers.ready = $q.all([
lawers.add(),
lawers.add(),
lawers.add(),
lawers.add()
]);
return lawers;
});
============================
so this app works fine without ionic-material ... but does not work when useing ionic-material
am I donig something wrong or is there anyhting wrong with ionic-material