Javascript 如何在转换到angular ui路由器上的另一个模式后关闭该模式
我用它来打开情态动词 我有两个情态动词的状态:Javascript 如何在转换到angular ui路由器上的另一个模式后关闭该模式,javascript,angularjs,modal-dialog,angular-ui-router,angular-ui,Javascript,Angularjs,Modal Dialog,Angular Ui Router,Angular Ui,我用它来打开情态动词 我有两个情态动词的状态: 'modal.first' 'modal.second' 我想要的是通过单击按钮关闭第一个模式,并将状态更改为'model.second' 问题是我只能关闭模式或更改状态(但第一个模式仍然打开) 此处说明定义: $stateProvider .state('modal.first', { url: '/first', onEnter: function ($state, $modal) {
'modal.first'
'modal.second'
'model.second'
问题是我只能关闭模式或更改状态(但第一个模式仍然打开)
此处说明定义:
$stateProvider
.state('modal.first', {
url: '/first',
onEnter: function ($state, $modal) {
$modal.open({
templateUrl: 'some_url',
controller: 'FirstCtrl',
resolve: {
//...
}
}
}).result.finally(function () {
$state.go('^');
});
}
})
第二个模态定义是相同的(状态名称为modal.second
和url/second
)
我试图关闭模态(并更改状态),如下所示:
(FirstController
)
但这不起作用。我只能选择一个或$state.go(…)
,或$modalInstance.close()
我想也许我应该更多地关注.finally()
块。但还是没有主意。谢谢
通过modals链接到官方常见问题解答:
UPDATE我不能在没有任何语句的情况下在finally中更改状态,因为我只需要单击按钮(并在任何其他情况下使
.go('^')
)即可更改状态。您可以定义服务,该服务保持modalInstance,并在再次调用打开时关闭它
angular.module('someModule')
.service("singleModal", function($modal) {
this.modalInstance = null;
this.open = function(options) {
if (this.modalInstance) {
this.modalInstance.close();
}
this.modalInstance = $modal.open(options);
return this.modalInstance;
};
})
您可以看到服务的简单示例(无ui引导)您可以定义服务,该服务保持modalInstance,并在再次调用打开时关闭它
angular.module('someModule')
.service("singleModal", function($modal) {
this.modalInstance = null;
this.open = function(options) {
if (this.modalInstance) {
this.modalInstance.close();
}
this.modalInstance = $modal.open(options);
return this.modalInstance;
};
})
您可以看到服务的简单示例(无ui引导)您可以定义服务,该服务保持modalInstance,并在再次调用打开时关闭它
angular.module('someModule')
.service("singleModal", function($modal) {
this.modalInstance = null;
this.open = function(options) {
if (this.modalInstance) {
this.modalInstance.close();
}
this.modalInstance = $modal.open(options);
return this.modalInstance;
};
})
您可以看到服务的简单示例(无ui引导)您可以定义服务,该服务保持modalInstance,并在再次调用打开时关闭它
angular.module('someModule')
.service("singleModal", function($modal) {
this.modalInstance = null;
this.open = function(options) {
if (this.modalInstance) {
this.modalInstance.close();
}
this.modalInstance = $modal.open(options);
return this.modalInstance;
};
})
您可以看到服务的简单示例(没有ui引导)如果可能,那么您可以在fiddle或plunker中复制此服务吗?如果可能,那么您可以在fiddle或plunker中复制此服务吗?如果可能,那么您可以在fiddle或plunker中复制此服务吗??