Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide examples for loading other angular modules #2

Closed
mariussoutier opened this issue May 16, 2013 · 6 comments
Closed

Provide examples for loading other angular modules #2

mariussoutier opened this issue May 16, 2013 · 6 comments

Comments

@mariussoutier
Copy link
Contributor

Any non-trivial project will make use of the other AngularJS modules (cookies, i18n, ...). Could you please provide examples what's the recommended way of loading them using WebJars and making sure that AngularJS is loaded before its submodules?

Currently I'm using a manual config along the lines of:

requirejs.config({
    shim: {
      'angular' : {'exports' : 'angular'},
      "angular-cookies" : { deps: ["angular"] }
    },
    priority: [
      "angular"
    ]
});

Thanks.

@huntc
Copy link
Contributor

huntc commented May 16, 2013

Hi @mariussoutier - the standard angularjs distribution comes bundled with many things. If you do something like:

jar tvf /usr/local/play-2.1.1/repository/cache/org.webjars/angularjs/jars/angularjs-1.0.5.jar

(depending on where your Play distro is)

...then you'll see what's available. Thus

define(["webjars!angular-cookies.js", function() {...

should be all that you need.

If there are things that you cannot find as a WebJar then please feel free to submit an issue/PR at the WebJars github repo. Thanks.

@huntc huntc closed this as completed May 16, 2013
@mariussoutier
Copy link
Contributor Author

Thanks for your answer.

I do use define("cookies", ["webjars!angular-cookies.js"], function() {}), but that alone doesn't guarantee the correct loading order. So often times, the app doesn't load because angular-cookies.js loads too early and fails with Cannot call method 'module' of undefined, because angular isn't defined yet.

@huntc
Copy link
Contributor

huntc commented May 17, 2013

Ah, yes, that's a problem. We need to enhance the angular webjar project so that it shims these other angular modules and declares their dependencies. Take a look at the bootstrap webjar src/main/resources to see what I mean. In bootstrap's case it declares a dependency on jQuery.

I'll reopen this and create a pr to attend to it (unless you beat me to it! ;-) ). Meanwhile if you declare a webjars!angular.js dependency in the define statement for the cookies module then you can work around the issue for now.

@huntc huntc reopened this May 17, 2013
@mariussoutier
Copy link
Contributor Author

Strangely, even that doesn't seem to work. So far the only reliable way was to set priority and dependencies explicitly in requirejs.config().

@huntc
Copy link
Contributor

huntc commented May 17, 2013

Actually that makes sense as both angularjs-config.js and angularjs will be loaded in parallel.... you'll need to use requirejs.config for now.

@huntc
Copy link
Contributor

huntc commented May 23, 2013

I'm going to take care of this issue here:

webjars/angularjs#11

@huntc huntc closed this as completed May 23, 2013
huntc pushed a commit to huntc/angular-seed-play-1 that referenced this issue May 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants