将数据传递给服务创建的离子模式

时间:2016-05-13 19:26:54

标签: javascript ionic-framework

我正在使用以下solution来创建Ionic Modal服务,但此刻,我发现很难将其传入我的模态中。我该怎么做才能纠正这个问题:

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将一个值输出到控制台中,因此其中有一些数据,但我不确定我是否以正确的方式从模式中访问它。

2 个答案:

答案 0 :(得分:1)

由于您已经在.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>

答案 1 :(得分:0)

这解决了它:

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