Ionic can not connect to dreamfactory

Hello, I have one of my problems is ionic can not connect to dreamfactory. I refer to the example here. Looking forward to the help from everyone.

app.js

.angular.module('starter', ['ionic'])
.constant('INSTANCE_URL', 'https://df-cinemavn.enterprise.dreamfactory.com')
.constant('APP_API_KEY', 'ac26a84d1f14e3ab9af61d5498c98fadd75cd62829b5c44100e9bd0d4f3958c')

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})

.run(['$cookies', 'APP_API_KEY', '$http', '$rootScope', '$window',
  function ($cookies, APP_API_KEY, $http, $rootScope, $window) {
    $http.defaults.headers.common['X-Dreamfactory-API-Key'] = APP_API_KEY;
    $http.defaults.headers.common['X-DreamFactory-Session-Token'] = $cookies.session_token;
  }
])

.config([
    '$httpProvider',
    function ($httpProvider) {
        $httpProvider.interceptors.push('httpInterceptor');
    }
])

.factory('httpInterceptor', [
    function () {
        return {
            request: function (config) {
                if (config.url.indexOf('/api/v2') > -1) {
                    config.url = INSTANCE_URL + config.url;
                };
                return config;
            }
        }
    }
])

.factory('Contacts', [
    '$resource',
    function ($resource) {
        return $resource('/api/v2/db/_table/contact?include_count=true&limit=15&offset=0&order=last_name+ASC', {
            query: {
                method: 'GET',
                isArray: false
            },
            create: {
                method: 'POST',
            },
            update: {
                method: 'PUT'
            },
            remove: {
                method: 'DELETE'
            }
        });
    }
])

.controller('ContactsCtrl', [
    '$scope', 'Contacts',
    function ($scope, Model) {
        Contacts.query({
        })
        .$promise.then(function (result) {
            $scope.contacts = result.resource
        }, function (error) {
        });
    }
]);

index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <script src="lib/ionic/js/ionic.bundle.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-cookies.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular-resource.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular-route.min.js"></script>
    <script src="cordova.js"></script>
    <script src="js/app.js"></script>
  </head>
  <body ng-app="starter" ng-controller="ContactsCtrl">

    <ion-pane>
      <ion-header-bar class="bar-stable">
        <h1 class="title">Ionic Blank Starter</h1>
      </ion-header-bar>
      <ion-content>
        {{contacts.id[1]}}
      </ion-content>
    </ion-pane>
  </body>
</html>

@hl1994 have you tried the DreamFactory forum here? Iā€™m sure someone in the DreamFactory user community has worked with Ionic and DreamFactory API.

2 Likes