Angular UI-Router Modification Removes Parent State

I am working on an angular application with a ui-router module. When I enter a certain state of the router, I show a modal dialog box, which then replaces my parent view. I would like to keep the parent view and show the modal as an overlay. Is there any way to do this using ui-router?

To give an example:

$stateProvider.state("clients.list", {
    url: "/list",
    templateUrl: "app/client/templates/client-list.tpl.html",
    controller: moduleNamespace.clientListController,
    resolve: {
        clients: function (ClientService) {
            return ClientService.all();
        }
    }
})
// This will replace "clients.list", and show the modal
// I want to just overlay the modal on top of "clients.list"
.state("clients.add", {
    url: "/add",
    onEnter: function ($stateParams, $rootScope, $state, ngDialog) {
        ngDialog.open({
            controller: moduleNamespace.clientAddController,
            template: "app/client/templates/client-add.tpl.html"
        });

        $rootScope.$on("ngDialog.closed", function (e, $dialog) 
              if ($state.current.name !== "clients.list") $state.transitionTo("clients.list");
        });
    }
})

thank

+4
source share
1 answer

I think the correct solution would be something like this:

$stateProvider.state("clients.list", {
    url: "/list",
    templateUrl: "app/client/templates/client-list.tpl.html",
    controller: moduleNamespace.clientListController,
    resolve: {
       clients: function (ClientService) {
          return ClientService.all();
      }
    }
})
.state("clients.list.add", {
    url: "^/add",
})

/add , ^. /list/add, ... ^ . , "" .

clients.list /client-list.tpl.html, ng-view, .

plunkr, , , .

+7

Source: https://habr.com/ru/post/1537591/


All Articles