0

In my MVC project i am using angularjs to produce single page application. every views produced by server load into ng-view by angular and maybe they have some ng-controller inside. so before they can be load i have handled and have deferred the view resolution, and then register some controller dynamically at run-time. the blow code describes this scenario

on the top of my page head i have this:

app.config(function ($controllerProvider) {
                // i hold app.controllerProvider to call later.
                app.controllerProvider = $controllerProvider;
    }

and

var routes={'URL1' , 'URL2' , 'URL3' , ... }
    app.config(function ($routeProvider) {
         routes.forEach(function (route) {
                    $routeProvider.when(route, {
                        templateUrl: route
                        ,
                        resolve: {
                            deps: PageResolver
                        }
                    });
                });
     }

and the resolver:

function PageResolver($q, $rootScope) {
   var deferred = $q.defer();


   app.controllerProvider.register('MyCTRL', [
     '$scope',
     function ($scope) {
       // ... some codes
   }]);


   deferred.resolve();
   return deferred.promise;
    }

these codes run and works fine ,but my problem is that the app.controllerProvider.register does not effect always! it means that i can't register controller dynamically?! or what is wrong?

3

0

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.