I am trying to open a modal dialog using Angular's ui-router as explained here.
The goal is for the dialog to be accessible anywhere, a url is not necessarily needed but it would be nice if I could link to a page with the dialog open.
Here is the broken sample:
http://plnkr.co/edit/BLkYME98e3ciK9PQjTh5?p=preview
clicking on "menu" should open the dialog from either page.
The routing logic:
app.config(function($stateProvider,$locationProvider, $urlRouterProvider, modalStateProvider) {
$urlRouterProvider.otherwise("/");
$locationProvider.html5Mode(true);
$stateProvider
.state("app", {
url: "",
abstarct: true,
views: {
"" : {
templateUrl: "main.html",
},
"header@app": {
templateUrl: "header.html"
},
"footer@app":{
templateUrl: "footer.html"
}
}
})
.state("app.home", {
url: "/",
templateUrl: "home.html",
})
.state("app.content", {
url: "/content",
templateUrl: "content1.html",
});
modalStateProvider.state("app.home.menu", {
template: "I am a Dialog!",
controller: function ($scope) {
$scope.dismiss = function () {
$scope.$dismiss();
};
}
});
});
It should not be a child of "app.home" since I want it to be accessible from anywhere. How can I achieve this?
You can do this with UI-Router Extras "Sticky States".
Updated plunk: http://plnkr.co/edit/GYMjzmBALlQNFWoldmxa?p=preview
Here is the UI-Router Extras modal demo: http://christopherthielen.github.io/ui-router-extras/example/stickymodal/#/
To update your plunk, I added UI-Router Extras:
I added a named ui-view for the app and one for the modal
Then I marked your app state as
sticky
and made your modal state a top-level state. The effect is that you can navigate from anyapp.*
state to the modal state... instead of exiting that state, it will only "inactivate" it, and it remains in the DOM.updated with response to question in comments:
You can do this yourself using a bunch of silly logic.