I am a Java developer and I am trying to create a frontend that use my web service. Following the tutorial on their site I must admit that I struggle with the concept of a module. Could someone explain why, what, when and how it should be used? If it has a "Java way" equivalent a comparison would also be highly appriciated.
From the Angular documentation:
A module is a collection of services, directives, filters, and configuration information.
A module can be an application, or it can be a collection of components that can be injected into other modules. In Angular, that's the way you group related things together so you can benefit from its dependency injection system.
For instance, your main app can be a module and you can break its parts into smaller, more cohesive packages (other modules). You can also use third-parties components (other modules) and inject them into your main app:
angular.module('app', ['app.controllers', 'app.directives', 'third-party-module1', 'third-party-module2');
Finally, I recommend this video tutorial from Dan Wahlin: Angular in 60-ish minutes.
General remark for beginners: forget that tutorial and start by this instead (from the egghead videos on -- I am still learning, too).
The module is your application in which you can register directives, controllers, services, filters, ..
You can use different modules and inject them into your main module (this is helpful to have a clearer structure.. and to use third party modules as libraries)..
angular.module('myApp', [
'myApp.controllers',
'myApp.filters',
'myApp.services',
'myApp.directives',
// 3rd party dependencies
'ui.bootstrap',
'btford.socket-io'
]).
This is a snippet from a project I am working on: myApp is the main module I am using (in the html file <html ng-app="myApp">), myApp.xxx are other modules which are injected into the main one. Finally there are 3rd party modules.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With