Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is module in Angularjs?

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.

like image 606
LuckyLuke Avatar asked Dec 05 '25 03:12

LuckyLuke


2 Answers

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.

like image 197
Michael Benford Avatar answered Dec 06 '25 15:12

Michael Benford


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.

like image 33
fusio Avatar answered Dec 06 '25 16:12

fusio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!