Ionic.Platform undefined in 1.0.0 beta 3


#1

Sorry, if this has already been answered but I am suddenly struggling with my code. I recently upgraded my project to 1.0.0 beta 3 from beta 1 and was manually bootstrapping my app using the following code:
require( [
‘cordova’,
‘ionic’,
‘angular’,
‘app’,
‘routes’
],

function(cordova, ionic, angular, app) {
    'use strict';

    var start  = function(){
        angular.bootstrap(document, [app['name']]);
    }

    var device = ionic.Platform.device();
    (document.body && device) ? start() : ionic.Platform.ready(start);        
}

);

As you can see I’m using require.js. This code worked fine but after upgrading to 1.0.0 beta 3 ionic.Platform is suddenly undefined. Has something changed or is there a dependency I am suddenly missing?
Any help would be extremely appreciative. This is also my first post on this (or any) forum so apologies if I’m just being stupid. Thanks


#2

Hey, welcome to the forum! Can you give this a try with the beta 4 or the nightly builds?


#3

Hey, thanks for the prompt response. I spent the whole of yesterday playing around with this to no success. I have tried updating to beta 4 and the issue still exists but I think it might be a larger issue to do with require.js. Let me try and explain…

For a while now, using 0.9.xx and 1.0.0 releases, I have experienced the following strange results.

  • The back button not appearing when it should i.e. when navigating between pages etc.
  • Views always being animated slide-right-left no matter if you were navigating back or not.
    I always put this down to a weird quirk of the ripple emulator, which I was using. However last night I created a brand new ionic project based on the ‘sidemenu’ and in the ripple emulator both of these points were fixed. I also noticed that in my old/main project the navbar title animation was never working and the whole app appears less smooth. I tried removing all 3rd party javascript paths from app.js such as Facebook.js), thinking there may be a conflict but still the problems occurred. I have bascially been using this seed project (https://github.com/jrowny/ionic-angular-cordova-require-seed) and more precisely the exact same main.js.

Sorry for the long winded response… but has anyone else had an issue with require.js and ionic/angular or loading the individual ionic javascript files instead of the ionic.bundle.min?


#4

Hmm, I’ve never used require.js before, but it seems that people have written about using it with angular and how they set things up.

http://thaiat.github.io/blog/2014/02/26/angularjs-and-requirejs-for-very-large-applications/

IMO, I don’t think you need require. It’s not as if you were writing a regular web app for desktop, so it seems like there would be less of a need for a script loader.


#5

Thanks so much for taking a look at this! After battling yesterday with various scenarios, I think I was trying to be too clever for my own good.

My original idea was to have a desktop web and mobile app all using the same code with a full, responsively designed front end. However those requirements (or my expectations) have changed and I think I will just stick to a mobile app with a well structured, pure angular approach and angular modules to separate functional areas. There seems to be a few good write ups about structuring such a layout out there. Hopefully in the future I can re-use much of my code if a desktop web app is also required.

If you have tips or links to structuring or creating a mobile and desktop app that would be much appreciated otherwise thanks again for your help.


#6

Check this one out, real world example


#7

I also get an undefined platform into a genymotion device simulator.
I use Ionic v1.0.0-beta.8 and this code

angular.module(‘ionic.example’, [‘ionic’])

.controller('MapCtrl', function($scope,$ionicPopup,$timeout) {

    ionic.Platform.ready(function(){
        var device = ionic.Platform.device();
        $ionicPopup.alert({
            title: 'Piattaforma: '+ device.platform
        });
    });
......

When i launch the app into the device i get an undefined message;
the plugin device is installed as you see into the screenshot

What i broken?
Thnak you in advance