Pass current scope to modalInstance when using controllerAs syntax

前端 未结 2 1076
南笙
南笙 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:53

    I need to open a modalInstace that shares the same scope as the current controller.

    Modal service creates inherited scope. And

    var modalInstance = $uibModal.open({
      templateUrl: 'addEditModal.html',
      scope: $scope
    });
    

    does not inject the scope but specifies parent scope for modal controller (otherwise root scope will be used as the parent).

    Since controllerAs was used on parent controller, modal controller will have access to inherited vm object on its scope.

提交回复
热议问题