ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

Binding works on web browser but not on iOS and Android application

Open Kae2312 opened this issue 12 years ago • 3 comments

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/[email protected]').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

Kae2312 avatar Apr 17 '14 07:04 Kae2312

Hello! Maybe you could post your logs here ... also can you access 0.0.0.0 from your device?

000panther avatar Apr 27 '14 21:04 000panther

Yes, and what is your cordova config.xml like? Maybe it isn't allowing remote requests.

ajoslin avatar Apr 29 '14 20:04 ajoslin

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

ionitron-bot[bot] avatar Sep 06 '18 09:09 ionitron-bot[bot]