ionic - $state.go 有参数问题
ionic - $state.go with params issue
我目前正在使用 Ionic 开发移动应用程序并使用 Phonegap 构建它。
我目前面临的问题与带参数的$state.go有关。发生的事情是我想传递一个组 ID 作为参数,当新屏幕加载时,它将获取这个组 ID 并从后端检索组信息,这将由服务处理。
注意:这在桌面上工作正常,但一旦我把它放在移动设备上就不行了。
下面是我正在使用的代码
创建组控件
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
};
});
管理组控件
angular.module('starter').controller('ManageGroupCtrl', function( $scope, $state, $stateParams, $ionicLoading, $ionicViewService, GroupService ){
$ionicViewService.clearHistory;
alert( $stateParams.id );
});
我的状态定义在app.js
$stateProvider.state('app.manage-group', {
url: 'manage-group/:id,
views: {
'menuContent' : {
templateUrl: "templates/manage-group.html",
controller: "ManageGroupCtrl"
}
}
});
至于我的模板文件 - manage-group.html | nav-header 应该按定义显示这两个图标。
<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>
所以我面临的情况是,ionicViewService 不清除历史记录并显示后退按钮(指向创建组),不加载任何 $scope 元素,甚至无法触发警报。
我的猜测是可能存在 Javascript 错误。我尝试使用 Phonegap 调试工具进行调试,但它没有显示任何错误,只有 console.log 条成功事件的消息。
所以我的问题是...
我传递的参数是否正确?
如何调试和查看错误日志?
任何帮助将不胜感激!
谢谢!
您正在正确传递状态参数,但听起来确实像是 javascript 错误导致您的代码中断。如果您是 运行 Android v4.4+,我建议您使用 Chrome 中的远程调试器来检查您的设备。需要进行少量设置,但在 Chrome 文档中对此进行了解释:
我目前正在使用 Ionic 开发移动应用程序并使用 Phonegap 构建它。
我目前面临的问题与带参数的$state.go有关。发生的事情是我想传递一个组 ID 作为参数,当新屏幕加载时,它将获取这个组 ID 并从后端检索组信息,这将由服务处理。
注意:这在桌面上工作正常,但一旦我把它放在移动设备上就不行了。
下面是我正在使用的代码
创建组控件
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
};
});
管理组控件
angular.module('starter').controller('ManageGroupCtrl', function( $scope, $state, $stateParams, $ionicLoading, $ionicViewService, GroupService ){
$ionicViewService.clearHistory;
alert( $stateParams.id );
});
我的状态定义在app.js
$stateProvider.state('app.manage-group', {
url: 'manage-group/:id,
views: {
'menuContent' : {
templateUrl: "templates/manage-group.html",
controller: "ManageGroupCtrl"
}
}
});
至于我的模板文件 - manage-group.html | nav-header 应该按定义显示这两个图标。
<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>
所以我面临的情况是,ionicViewService 不清除历史记录并显示后退按钮(指向创建组),不加载任何 $scope 元素,甚至无法触发警报。
我的猜测是可能存在 Javascript 错误。我尝试使用 Phonegap 调试工具进行调试,但它没有显示任何错误,只有 console.log 条成功事件的消息。
所以我的问题是...
我传递的参数是否正确?
如何调试和查看错误日志?
任何帮助将不胜感激!
谢谢!
您正在正确传递状态参数,但听起来确实像是 javascript 错误导致您的代码中断。如果您是 运行 Android v4.4+,我建议您使用 Chrome 中的远程调试器来检查您的设备。需要进行少量设置,但在 Chrome 文档中对此进行了解释: