Ui-router: same child view for every other state

Hey dudes,

i have maybe a little bit stupid question.
Is there a way to give each sate a same child view.

E.g. I have an own overlay, which could be over every other page/state.

It is frustrating to copy and paste the same child view to each other view.

Thank you and have a nice day!

You would have to create a new child view for each state in your $stateProvider, but have them all point to the same html file.

Hmm okay… but thats ugly grml

Veeeerrryy ugly…

:frowning: :frowning: :frowning:

Indeed, not the best solution, but we are at the mercy of Ui-router.

Maybe I can try to change the decorator for the views.

Adding a new view to the views object…

Thank you.

Solved it, saves code lines and time, but it is logically the same like givin’ all states this subview:

       $stateProvider
            .decorator('views', function (state, parent) {
                var views = parent(state),
                    results = views;

                results['childview@'] = {
                    templateUrl: childViewTemplate,
                    controller: 'childViewCtrl'
                };

                return results;
            })
2 Likes

How would you use this decorator to add the same child view to multiple states? What would the state declaration code look like?

1 Like