1

I'm using ui-router for my routing. I would like to know how I can dynamically change the parent templateUrl from a client state (edit state in this case).

angular.module('TestModule', ['ui.router'])
.config(['$stateProvider',  '$httpProvider',
    function ($stateProvider,  $httpProvider) {
        'use strict';
        $stateProvider
            .state('index', {
                abstract: true,
                views: {
                    '@': {
                        templateUrl: '/defaultLayout.html',
                        controller: 'layoutController'
                    },
                }]
            })

            .state('login', {
                parent: 'index',
                url: '/login',
                templateUrl: '/login.html',
                controller: 'loginController'
            })

            .state('edit', {
                url: '',
                parent: 'index',
              //Change the templateUrl from defaultLayout.html to userLayout.html

            })
            .state('edit.user', {
                url: '/edit/user',
                views: {
                    //code
                }

            });

    }])
.controller('layoutController', function () { })
.controller('layoutFluidController', function () { })
.controller('testCtrl', function () { 

 });

Please let me know how this can be achieved. Appreciate your help. Thanks in regards.

1 Answer 1

1

You can use another abstract parent 'index2' with different template url as .state('index2', { }) and use this as parent for the edit state as below,

angular.module('TestModule', ['ui.router'])
.config(['$stateProvider',  '$httpProvider',
    function ($stateProvider,  $httpProvider) {
        'use strict';
        $stateProvider
            .state('index', {
                abstract: true,
                views: {
                    '@': {
                        templateUrl: '/defaultLayout.html',
                        controller: 'layoutController'
                    },
                }]
            })
            .state('index2', {
                abstract: true,
                views: {
                    '@': {
                        templateUrl: '/defaultLayout2.html',
                        controller: 'layoutController'
                    },
                }]
            })

            .state('login', {
                parent: 'index',
                url: '/login',
                templateUrl: '/login.html',
                controller: 'loginController'
            })

            .state('edit', {
                url: '',
                parent: 'index2',
              //Change the templateUrl from defaultLayout.html to userLayout.html

            })
            .state('edit.user', {
                url: '/edit/user',
                views: {
                    //code
                }

            });

    }])
.controller('layoutController', function () { })
.controller('layoutFluidController', function () { })
.controller('testCtrl', function () { 

 });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.