Comments (6)
Leif,
The shim configuration simply sets up the dependencies for any module that may be loaded.
These modules do not get loaded unless they are requested.
The next section, within the array, are the modules that are being requested.
So, if we have
require
shim:
'controllers/gitHubController' : deps: ['app', 'services/gitHubService']
'controllers/personController' : deps: ['app', 'services/personService']
'controllers/personDetailsController': deps: ['app', 'services/personService']
'controllers/searchHistoryController': deps: ['app', 'services/messageService']
'directives/ngController' : deps: ['app']
'directives/tab' : deps: ['app']
'directives/tabs' : deps: ['app', 'directives/tab']
'filters/twitterfy' : deps: ['app']
'libs/angular-resource' : deps: ['libs/angular']
'responseInterceptors/dispatcher' : deps: ['app']
'services/gitHubService' : deps: ['app', 'services/messageService']
'services/messageService' : deps: ['app']
'services/personService' : deps: ['app']
'app' : deps: ['libs/angular', 'libs/angular-resource']
'bootstrap' : deps: ['app']
'routes' : deps: ['app']
'run' : deps: ['app']
'views' : deps: ['app']
[
'require'
'controllers/gitHubController'
], (require) ->
angular.element(document).ready ->
require ['bootstrap']
Only the gitHubController is requested to be loaded.
Following the dependency chain, the following will be loaded.
controllers/gitHubController
app
libs/angular
libs/angular-resource
services/gitHubService
services/messageService
Notice that personService
, routes
, views
, and others are not loaded. They are defined (configured) in the shim section, but in the sample above are not loaded.
require
is requested so after the modules are loaded we can request bootstrap
. When loading modules asynchronously, bootstrap needs to be called last. Requesting it in the callback ensures it is last.
I hope this helps.
Thanks,
Cary
from angularfun.
Thank you for this project and for the further explanation of main.coffee.
What if I wanted to include some third party js that is using jquery? Do I include it directly in the index template or ?
from angularfun.
Including it in the index template does work. The best way is to angularize everything, but in lieu of that, direct index inclusion does work.
from angularfun.
In the sample it loads all the scripts in the browser. Does this application load javascript(eg personController,PersonService etc) when required or I am missing something.
from angularfun.
Hey @bkak,
Yes the JavaScript files are loaded as-needed via RequireJS.
Keep in mind this is only necessary in the dev build. The prod build compiles everything into one file and doesn't need this functionality.
Thanks,
Cary
from angularfun.
Including jQuery with AngularJS apps requires jQuery to load prior to AngularJS.
Certainly the easiest way is to add jQuery to the index.html file.
RequireJS does provide the ability to include external files via its configuration, however.
Thanks,
Cary
from angularfun.
Related Issues (20)
- grunt prod and index.jade not working
- Need support for organization by module HOT 1
- npm install script not working in Windows HOT 6
- Where to use .constant and add additional external mods? HOT 14
- issues running after using jslove HOT 3
- hashed filenames and css HOT 3
- issue with Running "less:app" (less) task HOT 38
- npm install errors HOT 5
- Integrate grunt-newer HOT 3
- using stateProvider from ui-router HOT 3
- shimmer does not pick up newly added files within a watch HOT 1
- npm ERR! peerinvalid The package karma does not satisfy its siblings' peerDependencies requirements! ... HOT 2
- Heroku production HOT 1
- Heroku production HOT 4
- npm install fail on linux HOT 10
- grunt test failing on Linux HOT 1
- How to set my own bootstrap.js ? HOT 3
- grunt build fatal error HOT 11
- src/index.html need to be excluded for watch:basic task
- 'hash:images' in Gruntfile.coffee only 'hash' them, need to 'bust' them too
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angularfun.