I have to display a modal from the main menu. The modal displays correctly. But when I close the modal, i want the previous url to be displayed. This is the code for the modal:
.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
url: '/home',
templateUrl: 'views/home.html',
controller: 'HomeCtrl'
})
.state('pos',{
url: '/pos',
templateUrl: 'views/pos.html',
controller: 'PosCtrl'
})
.state('vAnalyze',{
url: '/vAnalyze',
templateUrl: 'views/vAnalyze.html',
controller: 'VAnalyzeCtrl'
})
.state('reportSetting',{
url: '/reportSettingModal',
onEnter: function($modal){
$modal.open({
templateUrl: 'views/reportSettingModal.html',
controller: 'ReportSettingModalCtrl'
});
}
})
.state('error', {
url: '/error',
templateUrl: 'lib/views/error.html',
controller: 'ErrorCtrl'
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/home');
})
.run(['AuthService', 'configSettings', '$rootScope', function (AuthService, configSettings, $rootScope)
{ // Apply Product Code
configSettings.productCode = 'VANALYZE';
AuthService.configProduct(configSettings.productCode);
$rootScope.$on('$stateChangeSuccess', function(event, to, toParams, from, fromParams) {
$rootScope.$previousState = from;
});
} ]);
This is the function to close the modal:
$scope.close = function() {
$uibModalInstance.close();
$state.go($rootScope.$previousState.name, {
url: $rootScope.$previousState.url,
templateUrl: $rootScope.$previousState.templateUrl,
controller: $rootScope.$previousState.controller
});
};
When I step into the code the url, templateUrl and controller all have the correct data. But the page is not displayed.
The page displayed when I close the modal is reportSettingModal.
What am I doing wrong?
$state.go($rootScope.$previousState.name)But the page was not changing. SO I thought if it was more explicit it would work. But it did not. I don't know what you mean by 'use a router for modals'. Typically, I have called modals from a page and when it closes the main page is visible. This modal is called from the main menu. - Gloria Santin