尝试关闭由close is not a function创建的模式窗口时收到$uibModal.open()

我已将问题简化为最少的代码:

    var app = angular.module('demoApp', ['ui.bootstrap']);

    app.controller('DemoContrller', function($scope, $uibModal) {
      var vm = this;
      var myModalInstance = null;

      vm.openModal = function() {

        myModalInstance = $uibModal.open({
                  animation: true,
                  templateUrl: 'modalTemplate.html',
                  scope: $scope // important - want to reuse current scope and controller and not create new
              }).result.then(function() {
                  console.log('fully closed with successful validation');
              });

      };


      vm.onApplyModal = function() {

          console.log('doing some validation and closing only if succeeded');

          // ??? close is not a function, myModalInstance is a Promise

          console.log(myModalInstance);
          myModalInstance.close();
      };

    })


请在这里查看我的Plunk:Cannot close uibmodal from a function in the same scope

最佳答案

 myModalInstance = $uibModal.open({
                  animation: true,
                  templateUrl: 'modalTemplate.html',
                  scope: $scope // important - want to reuse current scope and controller and not create new
              }).result.then(function() {
                  console.log('fully closed with successful validation');
              });


首先分配变量,然后链接:

 myModalInstance = $uibModal.open({
                  animation: true,
                  templateUrl: 'modalTemplate.html',
                  scope: $scope // important - want to reuse current scope and controller and not create new
              });
myModalInstance .result.then(function() {
                  console.log('fully closed with successful validation');
              });

关于javascript - 如果模式附加到同一作用域,如何从函数中关闭$ uibModal?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47631685/

10-12 07:20