【问题标题】:Load another view with a picture after taking the picture using ngCordova camera and Ionic使用 ngCordova 相机和 Ionic 拍照后加载另一个视图
【发布时间】:2016-01-14 20:50:09
【问题描述】:

我正在使用 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') 的一些内容,但它对我不起作用,或者我可能以错误的方式使用它,我可以做些什么来实现我正在寻找的东西,简而言之:拍摄一张照片并加载一个带有拍摄照片的页面。

问候。

【问题讨论】:

    标签: ios angularjs cordova ionic-framework ionic


    【解决方案1】:

    您可以使用$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

    【讨论】:

    • 它不起作用,一旦我将更改上传到 ionic,我的应用程序的某些功能没有改变,我会尝试找出导致问题的原因
    • 我修复了有关刷新项目以从 ionic view 应用程序检查它的问题,您的解决方案显然不起作用,一旦我拍照相机仍在工作,它不会关闭并重定向我到另一个视图。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-20
    • 2015-05-12
    • 1970-01-01
    • 1970-01-01
    • 2020-11-13
    • 1970-01-01
    相关资源
    最近更新 更多