需要一些指导。我正在将 angular-ui-bootstrap 与 php 和 mysql 一起使用。我想在每次模态加载时将链接列表(从 php mysql 生成)中的值传递给模态按钮。
HTML
// Below link is while-loop with php-mysql result
<a href="#" data-refno="<?php echo $r->wo_ref_no; ?>" ng-click="open()">Issue</a>
<script type="text/ng-template" id="SubmissionReminder.html">
<div class="modal-header">
<h3 class="modal-title">Submission Work Order Request</h3>
</div>
<div class="modal-body">
Please ensure quotation(s) or any document(s) related to this Work Order is ready for Procurement Unit to proceed accordingly.
</div>
<div class="modal-footer">
<button class="btn btn-default" type="button" ng-click="cancel()">Cancel</button>
<a href="issue.php?wo_ref={{ refno }}" class="btn btn-primary">Submit</a>
</div>
</script>
JS
app.controller('userWOController', function ($scope, $modal) {
$scope.animationsEnabled = true;
$scope.open = function () {
$scope.items = [];
var modalInstance = $modal.open({
animation: $scope.animationsEnabled,
templateUrl : 'SubmissionReminder.html',
controller: 'SubmissionReminder'
});
};
$scope.toggleAnimation = function () {
$scope.animationsEnabled = !$scope.animationsEnabled;
};
});
app.controller('SubmissionReminder', function ($scope, $modalInstance) {
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
});
我陷入了如何将值从触发器(a href)传递到模式按钮(a href)的困境。
最佳答案
您可以通过resolve
对象将数据发送到模态 Controller :
var modalInstance = $modal.open({
animation: $scope.animationsEnabled,
templateUrl : 'SubmissionReminder.html',
controller: 'SubmissionReminder',
resolve: {
refno: function () {
return {refno: $scope.refno};
}
}
});
然后从模态 Controller 中获取解析的refno
:
app.controller('SubmissionReminder', function ($scope, $modalInstance, refno) {
$scope.refno = refno().refno;
...
}
关于javascript - Angular-UI Bootstrap : pass value from Trigger's button to Modal's button,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32646470/