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

Define an AMD module if require.js is loaded #248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

m-amr
Copy link

@m-amr m-amr commented Oct 22, 2015

This pull request solve this Issue
#246

At requireJs.config
1- i added this line to the pathes
loadingBar:'bower_components/angular-loading-bar/build/loading-bar.min',

2-and i use shim to add angular as dependency for that module
loadingBar: {
exports: 'loadingBar',
deps:['angular']
},

i have my mainAngularModule called appModule;
what i am trying to do is to add the loadingBar module as a dependency in my appModule

var loadingBar = require('loadingBar');
console.log(loadingBar);
//display undefined

var appModule = angular.module('appModule', [
loadingBar.name
]);

it throw error because loadingBar is undefined
but when i added the module name as string it works

var appModule = angular.module('appModule', [
'chieffancypants.loadingBar'
]);

but by checking if define is a function then define an AMD module will solve the problem

* define AMD module
*/

if(typeof define === 'function') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use angular.isFunction

@faceleg
Copy link
Collaborator

faceleg commented Mar 16, 2016

LGTM but needs tests and the change I suggested. Thoughts @chieffancypants?

@chieffancypants
Copy link
Owner

I don't use AMD, so I can't really comment on the method used to support it. That said, I'd probably prefer it be done through the build process: https://github.com/bebraw/grunt-umd

The resulting code differs a bit from what is suggested here, and seems a bit more versatile. Here's an example output: https://github.com/angular-translate/bower-angular-translate/blob/master/angular-translate.js#L6-L20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants