0

I have a main view and a submain view. In submain, I agian have some subviews but these are suppose to be loaded dynamically i.e Round1,Round2,Round3.... is coming from dynamic value It may have 5 rounds or 4 or 3... How can I load those states dynamically ?

    angular
        .module('myApp', ['ngResource', 'ngRoute', 'ui.router'])
        .config(function($stateProvider, $urlRouterProvider) {
            $stateProvider
                .state('main', {
                    url: '/main',
                    templateUrl: 'views/mainView.html',
                    controller: 'mainCtrl'
                })
                .state('main.submain', {
                    url: '/sub_main',
                    templateUrl: 'views/subMainView.html',
                    controller: 'subMainCtrl'
                })
                .state('main.submain.Round1', {
                    url: '/Round_One',
                    templateUrl: 'views/subView.html',
                })
                .state('main.submain.Round2', {
                    url: '/Round_Two',
                    templateUrl: 'views/subView.html'
                })
                .state('main.submain.Round3', {
                    url: '/Round_Three',
                    templateUrl: 'views/subView.html'
                })
                .state('main.submain.Round4', {
                    url: '/Round_Four',
                    templateUrl: 'views/subView.html'
                })
                .state('main.submain.Round5', {
                    url: '/Overall_Feedback',
                    templateUrl: 'views/Round5View.html'
                })
            $urlRouterProvider.otherwise('/login');
        });
1
  • 2
    If you want to go by dynamic way , then instead of sub routes,add subroute as a route param to main route like /main/:subroute.Then access it in controller and based on that parameter load particular partial based on your need. Commented Jun 16, 2016 at 7:47

1 Answer 1

1

Please refer to the this Stack overflow question. This way you can add state to your $stateprovider dynamically

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.