I'm working with AngularAMD and I'm trying to "load" angular.easypichart module.
Here is my architecture:
--js
----app.js
----main.js
--lib
----angular.easypiechart.js
----ngload.js
In my main.js I've got that code:
require.config({
baseUrl: "js",
paths: {
'angular': 'https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular',
'angular-route': 'https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular-route',
'angularAMD': 'https://cdn.jsdelivr.net/angular.amd/0.2/angularAMD.min',
'ngload': '../lib/ngload',
'easypiechart': '../lib/angular.easypiechart'
},
shim: {
'angularAMD': ['angular'],
'angular-route': ['angular'],
'ngload': ['angularAMD'],
'easypiechart': ['angular']
},
deps: ['app']
});
And in my app.js :
define(['angularAMD', 'angular-route', 'easypiechart'], function (angularAMD) {
'use strict';
var app = angular.module('guess-bg', ['ngRoute']);
// config, etc.
return angularAMD.bootstrap(app);
});
But 'easypiechart' fail and I get the error Cannot read property 'module' of undefined
I don't get it because I used ['angular'] in shim for easypiechart.
I tried a lot of things such as
define(['angularAMD', 'angular-route', 'ngload!easypiechart']
Or
var app = angular.module('guess-bg', ['ngRoute', 'easypiechart']);
But keep getting errors. It's very obscur to me and I don't even understand how this 'ngload' works. I had no issues with angular-route by the way.
Anyway, I don't know how to simply load this module and it's really annoying...
Could you tell me what I'm missing?
You don't need
ngloadif you want to load module directly in your first requireJS module. It is mostly use for lazy load module for your app, for example in/some/random/route/you want to use an angular module, but only want it to be loaded here.ngloadwill do the trick.In your
app.jstry to remove'use strict';:It may because your enable
strictmode. So browser found thatangularobject wasn't defined anywhere around inapp.jstherefore you got error ofCannot read property 'module' of undefined.In another words,
angularobject does defined and available globally. But since you are in strict mode browser reject to use such global variable. If you still want to use strict mode. Usewindow.angularinstead :