如何从模态控制器中打开$ uibModal?

时间:2017-09-17 03:59:01

标签: angularjs modal-dialog angular-ui-bootstrap

我有这段代码:

app.controller('addEmployeeCtrl', function($scope, $uibModalInstance, newEmployee){
  $scope.addNewVehicle=function(){
    // I want to open a new modal here
  };    
});

1 个答案:

答案 0 :(得分:1)

您应该可以打开第二个模态,就像打开第一个模式一样......

$uibModal服务注入addEmployeeCtrl并调用$uibModal.open()传入另一个模态配置对象。

app.controller('addEmployeeCtrl', function($scope, $uibModalInstance, $uibModal, newEmployee){

  $scope.addNewVehicle = function(){

    var modalInstance = $uibModal.open({
      templateUrl: 'addVehicle.html',
      controller: 'addVehicleCtrl',
      controllerAs: 'vehicleVm'
      // Any other modal config properties here
    }

    modalInstance.then(closedCallback, dismissedCallback);

    function closedCallback(){
      // Do something when the modal is closed
    }

    function dismissedCallback(){
      // Do something when the modal is dismissed
    }
  };  
});