有没有办法在 angular-ui 模态中触发 .opened() ?

Is there a way to trigger .opened() in angular-ui modal?

我正在尝试了解如何为我的模式触发 .opened()。我想要发生的是,在我的模式中加载所有数据之后,我想 .opened() 被触发。我知道 opened() 在模式已经打开时触发,有没有办法改变它,比如可能只在我初始化控制器中的值后触发它?

    var modalInstance = $modal.open({
      templateUrl: 'myModalContent.html',
      controller: 'ModalInstanceCtrl'
    });

    modalInstance.opened.finally(function() {
           doSomething();
    });

阿斯达斯

angular.module('ui.bootstrap.demo').controller('ModalInstanceCtrl', function ($scope, $modalInstance, items) {

  init();

  function init() {
     // do initializations here....
     // then resolve the opened() function... but how?
  }

  $scope.ok = function () {
    $modalInstance.close($scope.selected.item);
  };

  $scope.cancel = function () {
    $modalInstance.dismiss('cancel');
  };
});

只需使用 'onOpen' 函数传递对象:

  $scope.ctrl = {
    onOpen: function() {
      console.log('open!');
    }
  };

    var modalInstance = $uibModal.open({
      animation: $scope.animationsEnabled,
      templateUrl: 'myModalContent.html',
      controller: 'ModalInstanceCtrl',
      size: size,
      resolve: {
        ctrl: function () {
          return $scope.ctrl;
        }
      }
    });

然后:

function init() {
  ctrl.onOpen();
}

http://plnkr.co/edit/wxwkV1cjT1gO8xGZDVgm?p=preview