Xavian Tracy
Xavian Tracy

Reputation: 127

ionic - $state.go with params issue

I'm currently working on a mobile app using Ionic and building it with Phonegap.

The problem I'm currently facing is related to $state.go with parameters. What happens is that I want to pass a group id as a parameter and when the new screen load, it will grab this group id and retrieve the group information from back end which will be handled by the service.

Note: This works fine on desktop but not once I put it on the mobile device.

Here's a peek at my codes that I'm using

CreateGroupCtrl

angular.module('starter').controller('AppCtrl', function( $scope, $state, $ionicSideMenuDelegate, $rootScope, $pusher, $ionicModal, $interval, GroupService ){
    $scope.submit = function(){
        // Create Group function to post data to database and receiving group id in return (no issue here)
        $state.go('app.manage-group', {id:group_id} ); // group_id is the id returned
    };
});

ManageGroupCtrl

angular.module('starter').controller('ManageGroupCtrl', function( $scope, $state, $stateParams, $ionicLoading, $ionicViewService, GroupService ){
        $ionicViewService.clearHistory;
        alert( $stateParams.id );
});

My state definition in app.js

$stateProvider.state('app.manage-group', {
    url: 'manage-group/:id,
    views: {
        'menuContent' : {
            templateUrl: "templates/manage-group.html",
            controller: "ManageGroupCtrl"
        }
    }
});

As for my template file - manage-group.html | The nav-header should show this two icons as defined.

<ion-nav-buttons side="left">
    <button menu-toggle="left" class="button button-icon icon ion-navicon"></button>
</ion-nav-buttons>
<ion-nav-buttons side="right">
    <button menu-toggle="right" class="button button-icon icon ion-person-stalker"></button>
</ion-nav-buttons>

So the situation I'm facing is that, ionicViewService does not clear history and shows the back button (points to create group), does not load any $scope elements and can't even trigger alert.

My guess is that there might be a Javascript error. I tried debugging with Phonegap Debug tool but it does not show me any error but only console.log messages of successful events.

So my question is ...

Am I passing parameters correctly?

How can I debug and view the error logs?

Any help will be greatly appreciated!

Thank you!

Upvotes: 3

Views: 3680

Answers (1)

lastcommit
lastcommit

Reputation: 106

You are passing state params correctly, but it does sound like a javascript error is causing your code to break. I would recommend using the remote debugger in Chrome to inspect your device if you are running Android v4.4+. There is a small amount of setup required, but it's explained in the Chrome docs:

https://developer.chrome.com/devtools/docs/remote-debugging

Upvotes: 1

Related Questions