2019/09/23 summary

1.bootstrap how the bidirectional transmission uibModal value between the sub-controllers and the master controller:

An example of the first show at work:

 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     }
Main function

 

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);
    }
}
Sub-controller

 

<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>
HTML button

 

(1) Firstly uibModal parameter value from the master controller will resolve pass into the sub-controller

Guess you like

Origin www.cnblogs.com/shoukaku/p/11575384.html