繁体   English   中英

使用ngCordova相机和Ionic拍照后再加载另一张照片

[英]Load another view with a picture after taking the picture using ngCordova camera and Ionic

我正在使用离子框架,正在尝试在拍照后加载另一个视图。

我有以下控制器:

.controller('SnapCtrl', function($scope, $cordovaCamera) {     
  $ionicPlatform.ready(function(){
    var options = { 
      quality : 75, 
      destinationType : Camera.DestinationType.DATA_URL, 
      sourceType : Camera.PictureSourceType.CAMERA, 
      allowEdit : false,
      encodingType: Camera.EncodingType.JPEG,
      targetWidth: 400,
      targetHeight: 400,
      popoverOptions: CameraPopoverOptions,
      saveToPhotoAlbum: false
    };

    $cordovaCamera.getPicture(options).then(function(imageData) {
      $scope.imgURI = "data:image/jpeg;base64," + imageData;      
    }, function(err) {
    // An error occured. Show a message to the user
    }); 
  })  
})

这是我页面的代码:

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

  // setup an abstract state for the tabs directive
    .state('tab', {
    url: '/tab',
    abstract: true,
    templateUrl: 'templates/tabs.html'
  })

  // Each tab has its own nav history stack:

  .state('tab.export', {
    url: '/export',
    views: {
      'tab-dash': {
        templateUrl: 'templates/tab-dash.html',
        controller: 'DashCtrl'
      }
    }
  })

  .state('tab.users', {
      url: '/users',
      views: {
        'tab-chats': {
          templateUrl: 'templates/tab-chats.html',
          controller: 'ChatsCtrl'
        }
      }
    })

  .state('tab.snapshot', {
    url: '/snapshot',
    views: {
      'tab-chats': {
        templateUrl: 'templates/tab-snapshot.html',
        controller: 'SnapCtrl'
      }
    }
  })

  /*  .state('tab.chat-detail', {
      url: '/chats/:chatId',
      views: {
        'tab-chats': {
          templateUrl: 'templates/chat-detail.html',
          controller: 'ChatDetailCtrl'
        }
      }
    })*/

  .state('tab.settings', {
    url: '/settings',
    views: {
      'tab-account': {
        templateUrl: 'templates/tab-account.html',
        controller: 'AccountCtrl'
      }
    }
  });

当用户访问快照页面时,以上代码将自动打开相机。 我想例如在拍照后(功能进入“快照”页面和控制器)加载另一个页面(例如“设置”)并显示在该页面上拍摄的照片。

我正在阅读有关$state.go('app.home')语句的内容,但它对我不起作用,或者我使用的方式有误,我该怎么做才能实现所需的功能几句话: 拍摄一张照片,并在其中加载一张带有已拍摄照片的页面。

问候。

您可以使用$state.go('tab.settings')重定向到该视图。

您应该能够将图像传递给此调用,例如:

$cordovaCamera.getPicture(options).then(function(imageData) {
      $scope.imgURI = "data:image/jpeg;base64," + imageData;   
      $state.go('tab.settings', {image: $scope.imgURI});
    },

这是具有更多详细信息的另一个答案: https : //stackoverflow.com/a/30511670/643779

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM