1

I am using angular js and ui router.

I am creating a wizard and I setup my ui-router with named views as below:

 .state('app.common.import', {
                url: '/import/:type',
                views: {
                    '': {
                        controller: 'ImportCommonCtrl',
                        templateUrl: 'views/tmpl/import/common.html'
                    },
                    'method@app.common.import': {
                        controller: 'ImportCommonCtrl',
                        templateUrl: 'views/tmpl/import/common/method.html'
                    },
                    'result@app.common.import': {
                        templateUrl: 'views/tmpl/import/common/result.html',
                        controller: 'ImportResultCtrl',
                    },

                    'upload@app.common.import': {
                        controller: 'ImportUploadCtrl',
                        templateUrl: 'views/tmpl/import/common/upload.html',
                        resolve: {
                            plugins: ['$ocLazyLoad', function ($ocLazyLoad) {
                                return $ocLazyLoad.load([
                                    'scripts/vendor/filestyle/bootstrap-filestyle.min.js'
                                ]);
                            }]
                        }
                    }
                }
            })

My issue is that all the controllers are loaded when I access to the url /import/:type ...

I would like to load the controller when the view is displayed.

I have tried $rootScope .$on('$viewContentLoaded', function(event, viewConfig) {

But it doesn't work. Is there a way to do this?

Thanks,

dalton5
  • 915
  • 2
  • 14
  • 28
  • possible duplicate of [AngularJS: $viewContentLoaded fired before partial view appears](http://stackoverflow.com/questions/27129829/angularjs-viewcontentloaded-fired-before-partial-view-appears) – Vineet Jul 14 '15 at 18:20
  • I tried with timeout but it's not working. – dalton5 Jul 14 '15 at 18:37
  • ... why can't you put the controllers behind different routes instead of all behind `/import/:type` – Mike Quinlan Jul 14 '15 at 20:45
  • Yes I think it will be the easiest thing. But I have my wizard that take the different views and my views must be named like: ui-view="method" ... – dalton5 Jul 15 '15 at 20:36

0 Answers0