Hi,
First of all, i’m new to angularjs and ionic.
Here’s my problem, i’m calling an api (develop in php) on localhost to get informations about the user connected.
Everything works fine, i can make a get request to my api and return a json response etc… So, on my “profile page”, i want to put all the informations about the user, i’m using {{ userInfos.first_name }}
, everything work fine when i test in a browser like google chrome, but i want to test on the ios or android application, it doesn’t work and there is nothing like if my controller wasn’t called.
here’s my code :
profile.html
<ion-pane>
<ion-header-bar class="bar-royal">
<h1 class="title">Moodress</h1>
</ion-header-bar>
<ion-content class="has-header">
<div ng-controller="ProfileController">
<ul class="list">
<li class="item" ng-bind-html="userInfos.username"></li>
<li class="item">{{ userInfos.first_name }}</li>
<li class="item">{{ userInfos.last_name }}</li>
<li class="item">{{ userInfos.email }}</li>
<li class="item">{{ userInfos.gender }}</li>
</ul>
</div>
</ion-content>
<ion-footer-bar align-title="left" class="bar-royal">
<div class="buttons">
<button class="button">Left Button</button>
</div>
<h1 class="title">Title!</h1>
<div class="buttons" ng-click="doSomething()">
<button class="button">Right Button</button>
</div>
</ion-footer-bar>
</ion-pane>
app.js
var moodress = angular.module('moodress', ['ionic', 'ui.router']);
moodress.config(function($stateProvider, $urlRouterProvider){
//$urlRouterProvider.otherwhise('/login');
$stateProvider
.state('/login', {
url: '/login',
templateUrl: 'partials/login.html'
})
.state('/profile', {
url: '/profile',
controller: 'ProfileController',
templateUrl: 'partials/profile.html'
});
$urlRouterProvider.when('', '/login');
});
moodress.controller('ProfileController', function($scope, profileFactory){
$scope.userInfos = [];
profileFactory.async().then(function(d){
$scope.userInfos = d;
});
});
moodress.factory('profileFactory', function($http){
var factory = {
async: function(){
var userInfo = $http.get('//0.0.0.0:3000/api/user_by_mail?email=yo@yo.com').then(function (response){
console.log(response);
alert(response.data.email);
return response.data;
});
return userInfo;
}
};
return factory;
});
moodress.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.StatusBar) {
// Set the statusbar to use the default style, tweak this to
// remove the status bar on iOS or change it to use white instead of dark colors.
StatusBar.styleDefault();
}
});
})
Here some screenshot :
On Google Chrome
On my emulators ios and android
I hope you can help me,
Thank you for your reading,
Answer2312