angular 里 factory 里使用自定义弹窗中,modalInstance.result.then 是什么作用
时间: 2023-11-22 18:56:32 浏览: 42
在 AngularJS 的 Factory 中使用自定义弹窗时,modalInstance.result.then() 方法用于处理模态对话框关闭后的结果。该方法接受两个函数作为参数,第一个函数将在模态对话框关闭并成功返回结果时调用,第二个函数将在模态对话框关闭并返回错误时调用。
例如,您可以这样使用 modalInstance.result.then() 方法:
```
angular.module('myApp').factory('myFactory', function($uibModal) {
var factory = {};
factory.openModal = function() {
var modalInstance = $uibModal.open({
templateUrl: 'myModalContent.html',
controller: 'MyModalController'
});
modalInstance.result.then(function(result) {
console.log('Modal closed with result:', result);
}, function(error) {
console.log('Modal closed with error:', error);
});
};
return factory;
});
```
在上面的代码中,modalInstance.result.then() 方法接受两个函数作为参数,一个用于成功返回结果,一个用于返回错误。在模态对话框关闭并成功返回结果时,第一个函数将被调用,并将结果作为参数传递给它。在模态对话框关闭并返回错误时,第二个函数将被调用,并将错误作为参数传递给它。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)