【发布时间】:2016-09-10 21:44:40
【问题描述】:
我对 ionic 非常陌生,并正在尝试实现相机功能。我在 routes.js 中有如下设置状态
.config(function($stateProvider, $urlRouterProvider) {
// Ionic uses AngularUI Router which uses the concept of states
// Learn more here: https://github.com/angular-ui/ui-router
// Set up the various states which the app can be in.
// Each state's controller can be found in controllers.js
$stateProvider
.state('capture', {
url: '/',
templateUrl: 'templates/capture.html',
controller: 'captureCtrl'
})
.state('selectColor', {
url: '/selectColor',
templateUrl: 'templates/selectColor.html',
controller: 'selectColorCtrl'
})
$urlRouterProvider.otherwise('/')
})
在 capture.html 中,我有一个图像可以点击使用下面的方法打开哪个相机
$scope.capturePhoto = function() {
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture($scope.onPhotoDataSuccess, $scope.onFail, {
quality: 30,
targetWidth: 600,
targetHeight: 600,
destinationType: navigator.camera.PictureSourceType.FILE_URI,
saveToPhotoAlbum: true
});
}
$scope.onPhotoDataSuccess = function(imageURI) {
console.log(imageURI);
$location.path('/selectColor');
}
$scope.onFail = function(message) {
//alert('Failed because: ' + message);
}
在照片成功时,控制权进入 $scope.onPhotoDataSuccess 方法,我试图使用 $location.path('selectColor') 移动到 /selectColor 但它没有正常呈现 selectColor.html 页面,我必须使用 $scope.$apply() 使其出现。
如果你已经在 Angular 中,我有 Angular 和 AFAIK 的经验,那么你不需要调用 $scope.$apply()
在我的情况下出了什么问题,是否有不同的方法可以在 ionic 而不是 $location.path() 中路由到另一个页面??
谢谢, 普拉提克
【问题讨论】:
-
你为什么不使用
$state.go? -
我比较熟悉 angular。 Angular-ui 对我来说也是新的。让我试一试。
标签: angularjs ionic-framework angular-ui-router angular-ui