Hi, 

I had to switch from ng-app to manual bootstrap in order to defer app init. 
till after an ajax call returns. The app works but DI no longer works in my 
Jasmine tests, likely because the pre-bootstrap API call fails and 
angular.bootstrap() is never invoked. If so, how can I inject a mock 
'constants' before angular.bootstrap() line?

Thanks,

-nikita


// Declare app level module which depends on filters, and services
angular.module('app', [
  'app.config',
  'app.services',
  'app.controllers',
  'app.directives',
  'ui.event',
  'ui.utils',
  'ngSanitize',
  'angularMoment',
  'infinite-scroll',
  'angularFileUpload'
]);

/**
 * manual bootstrap - defers app initialization until after constants are 
loaded from API
 */
angular.element(document).ready(function ()
{
  var initInjector = angular.injector(['ng']);
  var $http = initInjector.get('$http');

  $http.get('api/admin/constants')
      .then(function (response)
      {
        angular.module('app.config', []).constant('constants', 
response.data);
        // Add additional services/constants/variables to your app,
        // and then finally bootstrap it:
        angular.bootstrap(document, ['app']);

      });
});

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to