1.bootstrap的uibModal如何在子控制器和母控制器之间双向传值:
先展示工作中的一个实例:
1 public CreateAnswerKey() { 2 var $ctrl = this; 3 var choosenumberofdistractors = this.$uibModal.open({ 4 backdrop: true, 5 templateUrl: "template/ChooseNumberOfDistractors.html", 6 controller: "ChooseNumberOfDistractorsCtrl", 7 controllerAs: "ctrl", 8 resolve: { 9 numberofDistractors: () => this.numberofDistractors 10 } 11 }); 12 choosenumberofdistractors.result.then(function (numberofDistractors) { 13 $ctrl.numberofDistractors = numberofDistractors; 14 $ctrl.AnswerKeySelectedForm = "Form 1"; 15 $ctrl.QuestionAnswer = new Array(numberofDistractors); 16 $ctrl.FormList = new Array($ctrl.numberOfKeyForm); 17 for (var j = 0; j < $ctrl.numberOfKeyForm; j++) { 18 $ctrl.FormList[j] = "Form " + (j + 1); 19 for (var i = 0; i < $ctrl.numberofQuestions; i++) { 20 $ctrl.QuestionAnswer[i + j * $ctrl.numberofQuestions] = (numberofDistractors == 5) ? { A: false, B: false, C: false, D: false, E: false, F: null, G: null, H: null, I: null, J: null, FormID: $ctrl.FormList[j] } : 21 { A: false, B: false, C: false, D: false, E: false, F: false, G: false, H: false, I: false, J: false, FormID: $ctrl.FormList[j] }; 22 } 23 } 24 }); 25 }
export class ChooseNumberOfDistractorsCtrl { static readonly $inject = [ "numberofDistractors", "$http", "routeConfig", "$uibModalInstance", "errorHandler", ]; constructor( public numberofDistractors: number, private $http: IHttpService, private routeConfig: RouteConfig, private $uibModalInstance: IModalServiceInstance, private errorHandler: ErrorHandler) { } FiveDistractors() { this.numberofDistractors = 5; this.$uibModalInstance.close(this.numberofDistractors); } TenDistractors() { this.numberofDistractors = 10; this.$uibModalInstance.close(this.numberofDistractors); } }
<div class="col-xs-3" ng-show="ctrl.selectedExam.Id || ctrl.newExamId"> <button type="button" class="btn-default btn" ng-click="ctrl.CreateAnswerKey()" ng-disabled="!ctrl.numberofQuestions || !ctrl.numberOfKeyForm || (ctrl.numberOfKeyForm > 99)">Create AnswerKey</button> </div>
(1)首先通过uibModal参数中的resolve将值从母控制器传进子控制器