我正在使用UI-Router和angular bootstrap-ui。我有一個狀態設置來創建模式'onEnter'。當我試圖關閉模式'onExit'時,我現在遇到了問題。這是基本狀態。當輸入'items.detail'時它會打開一個模式,當模式關閉或解散時它將轉換爲'項目'。需要關閉狀態退出模式
.state('items.detail', {
url: '/{id}',
onEnter: function ($stateParams, $state, $modal, $resource) {
var modalInstance = $modal.open({
templateUrl: 'views/modal/item-detail.html',
controller: 'itemDetailCtrl'
})
.result.then(function() {
$state.transitionTo('items');
}, function() {
$state.transitionTo('items');
});
}
})
我試過使用onExit處理程序就像這樣。但是無法訪問modalInstance或模式從該處理程序中獲取的作用域。我試圖注入的一切都是未定義的。
.state('items.detail', {
url: '/{id}',
onEnter: function ($stateParams, $state, $modal, $resource) {
var modalInstance = $modal.open({
templateUrl: 'views/modal/item-detail.html',
controller: 'itemDetailCtrl'
})
.result.then(function() {
$state.transitionTo('items');
}, function() {
$state.transitionTo('items');
});
},
onExit: function ($scope) {
controller: function ($scope, $modalInstance, $modal) {
$modalInstance.dismiss();
};
}
})
從我的模態的控制器我試着聽狀態的變化。
$scope.$on('$stateChangeStart', function() {
$modalInstance.dismiss();
});
我既$範圍嘗試這樣做。$上$ rootScope。$上這兩個工作,但他們最終會被調用的任何國家之間的每一次我的轉變。然而,只有在我打開模式後纔會發生這種情況。
如果最後一點不清楚......當我刷新我的角度應用程序時,我可以在所有其他狀態之間進行轉換,但不會調用此偵聽器事件,但在打開該模式後,所有狀態更改都會被調用聽衆,即使在模式關閉後。
謝謝,這似乎是一個更好的解決方案,並且很容易實現。 – Constellates
歡迎,祝你好運:) – Armen
等待,我想在這個瞬間,我誤解了發生了什麼。現在我下班回家了,它並沒有關閉狀態改變的模式,我猜測它從來沒有或者我改變過一些東西。無論如何,當這個狀態離開時,什麼部分會關閉模態? – Constellates