Angular-UI Bootstrap:将Trigger的按钮值传递给Modal的按钮

时间:2015-09-18 07:40:20

标签: javascript angularjs twitter-bootstrap

需要一些指导。我正在使用带有php和mysql的angular-ui-bootstrap。我希望每次模态加载时都将链接列表中的值(从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)中的值传递给模态按钮(href)。

1 个答案:

答案 0 :(得分:1)

您可以将数据发送到模态控制器,通过resolve对象:

var modalInstance = $modal.open({
  animation: $scope.animationsEnabled,
  templateUrl : 'SubmissionReminder.html',
  controller: 'SubmissionReminder',
  resolve: {
    refno: function () {
      return {refno: $scope.refno};
    }
  }
});

然后从模态控制器中解析refno

app.controller('SubmissionReminder', function ($scope, $modalInstance, refno) {
  $scope.refno = refno().refno;
  ...
}