Software Development

AngularJS use service from another module

[wp_ad_camp_5]

This post demonstrates how to use services from another module.

Contents

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.

[wp_ad_camp_4]

[wp_ad_camp_2]

Main page

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

[wp_ad_camp_3]

Sample Output

Download the codes

[wp_ad_camp_1]

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

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like