D
D
DarthJS2015-11-17 10:52:27
Angular
DarthJS, 2015-11-17 10:52:27

How to build complex Url, store and transfer their state?

Hello!
I am making an app and there is a need to build links like /stateA/IdA/stateB/IdB with which the problem actually arose
What I do:
* directives with local scopes in templates, configs with states in controllers

.state(stateZero, {
    url: '/list',
    template: < table config="config"> < /table>,
    controller: function () {}
})

.state(stateA.listA, {
    url: '/list/:id',
    template: < table id = 'id' config="config"> < /table>,
    controller: function () {}
})

.state(stateB.listB, {
    abstract: true,
    url: '/list/:prevID/listB/:id',
    template: < tabs id = "id" prevID = "prevID" config="config"> < /tabs>,
    controller: function () {}
})

.state(stateB.listB.tabA, {
    abstract: true,
    url: '/tabA',
    template: < input id = "id" prevID = "prevID" config="config"> < /input>,
    controller: function () {}
})

What happens, my button looks like this
<button ui-sref="{{state.sref}}({id:id, prevID: prevID})"

The configs contain data about the states for the button. It turns out that I drag two IDs along the state controllers, catch them and insert them into the button. Often there is a problem when it is necessary to go back along the same path - I lose IDs.
I also tried to pass data to params: {id: '', prevID: '', test: 'test'} and catch it in $state.get() but somehow it turns out that in states B I see empty properties, for except for the test, which is written in pens.
I tried to pull the url from $location, cut it and take the id, but I considered it a perversion and stopped doing it.
Who has experience in building complex urls, tell me how to do it right, if there are links to examples, it would be great in general, since I rustled the whole net and usually simple examples.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0X12eb, 2015-11-21
@0X12eb

I sketched an exemplary implementation: Plnkr
To track state changes and pull parameters from the states of descendants, you can use this option:

controller: function($state, $scope, $rootScope) {
        $rootScope.$on("$stateChangeStart", function() {
          $scope.stateParams = $state.params;
        });
      }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question