0

AngularJS use service from another module

This post demonstrates how to use services from another module.

Software Requirements

  • Windows 10
  • Notepad++ or Brackets
  • AngularJS 1.6.2
  • Main HTML must be HTML5-compliant (optional)

Angular Modules

You SPA applications may be broken down into several modules. Each module contain related codes. Note that, ideally, there should only be one main module whose name is used with data-ng-app directive.

Below is our myapp.js. It has two (2) modules – myapp.util and myapp.

myapp is your main module and  it needs to use the calc service from myapp.util.

Main page

Our main page is a simple HTML file that shows the sum, difference, dividend, and product of 10 and 14.

Sample Output

Download the codes

https://github.com/Turreta/AngularJS-use-service-from-another-module