Angular JS – Config/Factory/Service/Controller Example (All in One)

This example provides the usage of following components in angular -js., in a simple example.

The following example provides the details of all the below components, so we can use it for an enterprise application very easily.

  • Config
  • Factory
  • Service
  • Constants
  • Controller

Config – Config is nothing but the Configuration block which is called during angular-js startup.

  1. Set a default value in configuration.
  2. Initialise a factory method in configuration.
  3. Inject a directive during angular js startup in the application.

Angular JS(Config/factory/Service/controller) Example:

HTML Page Output:

——————————————————————————————————

AngularJS – All in One- Simple Example

AngularJS Sample Application – {{siteHeader}}

Enter anything to count:


Word Count: {{wordcountresult}}

Letter Count: {{lettercountresult}}

—————————————————————————————————

Once the HTML/Angular-JS is executed, the console.log(“”) statements will be printed in the browser developer tools->console tab

(Press F12 for most browsers)

It will display the Order of methods initialised and called for the code above.

Console Output

Called Provider Implmentation — WordCountProvider (Called Angular-JS Initialization)
Called Factory Implmentation — LetterCountFactory
Called Service Implmentation — AbstractService
Called Controller — MyControllertutorialflow.com

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *