AngularJS Arrays and Module


AngularJS arrays are like JavaScript arrays.

Example: AngularJS arrays

<!DOCTYPE html/>
<html ng-app>
          <script src="Scripts/angular.min.js" type="text/javascript"></script>
          <div ng-app="" ng-init="points=[10,15,19,2,4]">
               <p>The third item in the array is = {{points[2]}}</p>

The third item in the array is = 19

Module in AngularJS

  • Module is a container for different part of your container. It can contain controllers, services, directives, filters etc.
  • You can consider a module as a main() method, same as in C# or in Java.
  • Angular apps don't have a main method, instead modules declaratively specify how an application should be load for execution.
Some of the advantages of module are as follows:
  • Declarative process for creating the module is easier to understand.
  • Modules are reusable.
  • The modules can be loaded in any order.
  • Modules are fast with respect to unit tests because it loads relevant modules only.
AngularJS framework provides an angular object. With the help of module() method of angular object you can create the module. The first parameter is the name of the module that we want to create and the second parameter shows the dependency of the module. A module can dependent on other module.

var app = angular.module("myModule", [ ]);

According to the above code, it will create module name "myModule" and it will not dependent on any external module due to second parameter as an empty array.