0

So I have an AngularJS application in which I am attempting to bootstrap only after all of the data for the application is loaded. I need to be able to make the requests in JSONP format so I am attempting to load the $resource module by using a .run statement.

Here's how it looks:

(function(){

        // Define our app
            app = angular.module("GRT", ["ngResource", "ngRoute"])

            .run(function($resource){
                console.log($resource);
            })

        // Configure our route provider and location provider
            .config(function($routeProvider, $httpProvider, $locationProvider) {
                $routeProvider.
                when('/', {
                    templateUrl: 'views/home.html'
                })
                .when('/customer-site-registration', {
                    templateUrl: "views/customer-site-registration.html",
                    controller: "customerSiteRegistration"
                })
                .otherwise({
                    redirectTo: '/'
                });

                // $locationProvider.html5Mode(true);
            });
    }())

Basically no matter what I do it wont run that run block. Any ideas?

StephenRios
  • 2,192
  • 4
  • 26
  • 42

1 Answers1

1

Run blocks do not run until the Angular application is bootstrapped. I needed this to run before the bootstrapping.

In this setup the ng-app attribute was removed from the enclosing DOM element to prevent auto-bootstrapping and I was doing it manually after running some code.

Since I was only using it to get access to resource, I instead grabbed it manually like this:

var $resource = angular.injector(["ngResource"]).get("$resource");

Hope this helps someone else!

StephenRios
  • 2,192
  • 4
  • 26
  • 42