【发布时间】:2015-07-24 11:39:37
【问题描述】:
我有一个问题,因为我需要在 ui-bootstrap 模态关闭(并已完成动画)时执行一个方法。我不知道如何正确地写承诺。到目前为止我有这个(在 TypeScript 中):
public open(attrs, opts) {
var scope = this.rootScope.$new();
angular.extend(scope, attrs);
opts = angular.extend(opts || {}, {
backdrop: false,
scope: scope,
templateUrl: 'splash/content.html',
windowTemplateUrl: 'splash/index.html'
});
this.modalInstance = this.modal.open(opts);
this.modalInstance.result.then(
function() {
console.log("1");
},
function() {
console.log("2");
},
function() {
console.log("3");
});
}
public close() {
if (this.modalInstance != null && this.modalInstance != undefined) {
this.modalInstance.close();
}
}
我尝试将 .result 附加到 close 方法,但显然没有退出:似乎只有 open 方法返回一个承诺。谁能帮我吗?控制台中只显示“1”,我认为这是开放解析。
【问题讨论】:
-
.result是通过.close或.dismiss关闭模式时的解析。从文档中 - “当模式关闭时解决的承诺并在模式被关闭时被拒绝”
标签: javascript angularjs twitter-bootstrap promise angular-ui-bootstrap