Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs ionic:$location.path仅在使用$scope.$apply()时有效_Angularjs_Ionic Framework_Angular Ui Router_Angular Ui - Fatal编程技术网

Angularjs ionic:$location.path仅在使用$scope.$apply()时有效

Angularjs ionic:$location.path仅在使用$scope.$apply()时有效,angularjs,ionic-framework,angular-ui-router,angular-ui,Angularjs,Ionic Framework,Angular Ui Router,Angular Ui,我对爱奥尼亚非常陌生,并尝试实现摄像头功能。我在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

我对爱奥尼亚非常陌生,并尝试实现摄像头功能。我在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);
  }
在photo success中,控件将转到$scope.onPhotoDataSuccess方法,我尝试使用$location.path('selectColor')移动到/selectColor,但它无法正常呈现selectColor.html页面,我必须使用$scope.$apply()使其出现

我有angular和AFAIK的经验,如果您已经在angular中,那么您不需要调用$scope。$apply()

在我的例子中出现了什么问题?在ionic中,是否有其他方法来路由到另一个页面而不是$location.path()

谢谢,
PrAtEKE/P> > P>这完全取决于当你考虑是否“内有角”时,光数据被调用的范围。考虑到它可能是从navigator.camera调用的,而navigator.camera不在angular功能中的某个地方(ng click、ng submit等),您必须继续调用
$scope.$apply()
,才能使其正常工作。没有问题,这就是它应该如何工作的。

< P>这完全取决于当你考虑你是否在“角度之内”时,从哪里调用光数据。考虑到它可能是从navigator.camera调用的,而navigator.camera不在angular功能中的某个地方(ng click、ng submit等),您必须继续调用
$scope.$apply()
,才能使其正常工作。没什么问题,这就是它的工作原理。

为什么不使用
$state.go
呢?我对angular比较熟悉。角度用户界面对我来说也是新的。让我试一试。为什么不使用
$state.go
?我更熟悉angular。角度用户界面对我来说也是新的。让我试一试。