将数据传递给由服务创建的Ionic模态

Passing on data to Ionic modal created by a service

本文关键字:创建 Ionic 模态 服务 数据      更新时间:2023-09-26

我正在使用以下解决方案来创建Ionic Modal服务,但目前,我发现很难将a传递到我的模态中。我能做些什么来纠正这个问题:

controller.js

$scope.confirmBookingModal = function(val) {
  console.log(val);
  ModalService.show('templates/modals/confirm-booking.html', 'ConsumerBusinessProfileCtrl as vm', val);
}

模态

<ion-modal-view ng-controller="ConsumerBusinessProfileCtrl">
  <ion-header-bar>
    <h1 class="title">Confirm</h1>
    <div class="buttons">
      <button class="button button-clear" ng-click="closeModal()">Close</button>
    </div>
  </ion-header-bar>
  <ion-header-bar class="bar bar-subheader bar-dark modal-padding">
    <h1 class="title">{{ vm.val }} services booked at £110 for 2 hours</h1>
  </ion-header-bar>

  <ion-content>
  </ion-content>
</ion-modal-view>

val向控制台输出一个值,所以其中有一些数据,但我不确定我是否以正确的方式从模态访问它。

由于您已经在.show()方法调用中指定了控制器,因此在模态模板中不需要它。将模式模板更改为:

<ion-modal-view>
  <ion-header-bar>
    <h1 class="title">Confirm</h1>
    <div class="buttons">
      <button class="button button-clear" ng-click="closeModal()">Close</button>
    </div>
  </ion-header-bar>
  <ion-header-bar class="bar bar-subheader bar-dark modal-padding">
    <h1 class="title">{{ vm.val }} services booked at £110 for 2 hours</h1>
  </ion-header-bar>

   <ion-content>
   </ion-content>
</ion-modal-view>

这修复了它:

$scope.confirmBookingModal = function() {
  var vm = $scope;
  ModalService.show('templates/modals/confirm-booking.html', 'ConsumerBusinessProfileCtrl as vm');
}