Pass current scope to modalInstance when using controllerAs syntax

前端 未结 2 1077
南笙
南笙 2020-12-11 15:45

I\'m using controllerAs syntax to avoid a $scope soup in my controllers, and also using ui.bootstrap to present a modal view.

I need to open a modalInstace that sh

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-11 15:51

    Not sure If I understood correctly, but I got it working by passing/injecting the current 'controllerAs' in the resolve parameter

    var modalInstance = $uibModal.open({
          templateUrl: 'addEditModal.html',
          controller: 'AudioItemAddEditCtrl as vm',
          resolve: {
            parent: function(){
                return vm
            }
        }
        });
    

    And then, in the AudioItemAddEditCtrl...

    var AudioItemAddEditCtrl = function(parent, AudioItemService, $ModalInstance) {
    ...
    }
    

    Then I'm able to use 'parent' to access the parent controller scope directly.

    Hope this helps someone else.

提交回复
热议问题