我正在使用以下solution创建一个 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()
方法调用中指定了 Controller ,因此在模态模板中不需要它。将模态模板更改为:
<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>
关于javascript - 将数据传递给服务创建的 Ionic 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37217907/