2

Everything is very "fresh" right now. I've got the angular seed project and I'm using the async index page. When I add a reference for angular-bootstrap It blows up. This doesn't happen when I don't load async style.

How can I use AngularUI bootstrap with the $script loader?

The errors I'm getting are:

Uncaught TypeError: Object #<Object> has no method 'controller' ui-bootstrap-0.2.0.js:9
(anonymous function) ui-bootstrap-0.2.0.js:9

Uncaught Error: No module: ui.bootstrap.collapse new-job-order:18
(anonymous function) new-job-order:18
d new-job-order:18
(anonymous function) new-job-order:18
(anonymous function) angular.js:2754
forEach angular.js:133
loadModules angular.js:2750
(anonymous function) angular.js:2755
forEach angular.js:133
loadModules angular.js:2750
(anonymous function) angular.js:2755
forEach angular.js:133
loadModules angular.js:2750
(anonymous function) angular.js:2755
forEach angular.js:133
loadModules angular.js:2750
createInjector angular.js:2692
bootstrap angular.js:959
(anonymous function) new-job-order:45
o new-job-order:29
e.onload.e.onerror.e.(anonymous function) new-job-order:29

Update

My code is really just the seed template, using the index-async.html file. Then I added (or tried to) bootstrap-ui. The relevant parts are:

  <script>
    // include angular loader, which allows the files to load in any order
    /*
     AngularJS v1.0.0rc1
     (c) 2010-2012 AngularJS http://angularjs.org
     License: MIT
    */
    'use strict';(function(i){function d(c,a,e){return c[a]||(c[a]=e())}return d(d(i,"angular",Object),"module",function(){var c={};return function(a,e,f){e&&c.hasOwnProperty(a)&&(c[a]=null);return d(c,a,function(){function b(a,b,d){return function(){c[d||"push"]([a,b,arguments]);return g}}if(!e)throw Error("No module: "+a);var c=[],d=[],h=b("$injector","invoke"),g={_invokeQueue:c,_runBlocks:d,requires:e,name:a,provider:b("$provide","provider"),factory:b("$provide","factory"),service:b("$provide","service"),
    value:b("$provide","value"),constant:b("$provide","constant","unshift"),filter:b("$filterProvider","register"),directive:b("$compileProvider","directive"),config:h,run:function(a){d.push(a);return this}};f&&h(f);return g})}})})(window);

    // include a third-party async loader library
    /*!
     * $script.js v1.3
     * https://github.com/ded/script.js
     * Copyright: @ded & @fat - Dustin Diaz, Jacob Thornton 2011
     * Follow our software http://twitter.com/dedfat
     * License: MIT
     */
    !function(a,b,c){function t(a,c){var e=b.createElement("script"),f=j;e.onload=e.onerror=e[o]=function(){e[m]&&!/^c|loade/.test(e[m])||f||(e.onload=e[o]=null,f=1,c())},e.async=1,e.src=a,d.insertBefore(e,d.firstChild)}function q(a,b){p(a,function(a){return!b(a)})}var d=b.getElementsByTagName("head")[0],e={},f={},g={},h={},i="string",j=!1,k="push",l="DOMContentLoaded",m="readyState",n="addEventListener",o="onreadystatechange",p=function(a,b){for(var c=0,d=a.length;c<d;++c)if(!b(a[c]))return j;return 1};!b[m]&&b[n]&&(b[n](l,function r(){b.removeEventListener(l,r,j),b[m]="complete"},j),b[m]="loading");var s=function(a,b,d){function o(){if(!--m){e[l]=1,j&&j();for(var a in g)p(a.split("|"),n)&&!q(g[a],n)&&(g[a]=[])}}function n(a){return a.call?a():e[a]}a=a[k]?a:[a];var i=b&&b.call,j=i?b:d,l=i?a.join(""):b,m=a.length;c(function(){q(a,function(a){h[a]?(l&&(f[l]=1),o()):(h[a]=1,l&&(f[l]=1),t(s.path?s.path+a+".js":a,o))})},0);return s};s.get=t,s.ready=function(a,b,c){a=a[k]?a:[a];var d=[];!q(a,function(a){e[a]||d[k](a)})&&p(a,function(a){return e[a]})?b():!function(a){g[a]=g[a]||[],g[a][k](b),c&&c(d)}(a.join("|"));return s};var u=a.$script;s.noConflict=function(){a.$script=u;return this},typeof module!="undefined"&&module.exports?module.exports=s:a.$script=s}(this,document,setTimeout)

    // load all of the dependencies asynchronously.
    $script([
      'lib/angular/angular.js',
      'lib/angular/angular-resource.js',
      'lib/angular-ui/ui-bootstrap-0.2.0.js',
      'js/app.js',
      'js/services.js',
      'js/controllers.js',
      'js/filters.js',
      'js/directives.js'
    ], function() {
      // when all is done, execute bootstrap angular application
      angular.bootstrap(document, ['myApp']);
    });
  </script>

Then in app.js I do:

angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives', 'ngResource', 'ui.bootstrap']).
  config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
    $routeProvider.when('/view1', {templateUrl: 'partials/partial1.html', controller: MyCtrl1});
    $routeProvider.when('/view2', {templateUrl: 'partials/partial2.html', controller: MyCtrl2});
    $routeProvider.otherwise({redirectTo: '/view1'});
    $locationProvider.html5Mode(true).hashPrefix('!');
  }]);
Mike Haas
  • 2,273
  • 3
  • 25
  • 30

2 Answers2

2

I don't think it is specifically linked to the bootstrap project, at the moment AngularJS simply doesn't allow async loads of modules, check this thread: How is modularity mitigated in AngularJS?.

Basically all the AngularJS modules must be loaded before application is bootstrapped. So you need to make sure that all the modules you depend upon are fully loaded before your start AngularJS application.

Would love to help more but based just on the error code it is next to impossible to say more.

Community
  • 1
  • 1
pkozlowski.opensource
  • 117,202
  • 60
  • 326
  • 286
  • I've updated my post to include the relevant code. I thought that the $script.js part is set up so that it loads all the files, then boostraps angular so that way it can use async. – Mike Haas Mar 19 '13 at 00:44
  • @user45763 I'm really not sure what is going on here... The only thing that might be worth exploring is the fact that you are including dist file without embedded templates. Try changing `ui-bootstrap-0.2.0.js` to `ui-bootstrap-tpls-0.2.0.js`. More info here: https://github.com/angular-ui/bootstrap/tree/gh-pages#build-files – pkozlowski.opensource Mar 19 '13 at 09:16
  • The github repo page makes it sound as if I won't be able to use my own custom partials if I use the library with them embedded. I want to be able to customize that. – Mike Haas Mar 19 '13 at 13:32
0

Turns out it's the $script loader's fault, here's the github issue explaining the problem: https://github.com/angular/angular-seed/issues/40

To solve this, just grab the updated to the latest version loading script from here: https://github.com/DemonShi/angular-seed/blob/2a8b3465574e9fad208b64050ad30e9c45df4ac9/app/index-async.html

Roman Kolpak
  • 1,942
  • 21
  • 25