Skip to content
Learn Netverks

Lesson

Step 18/36 50% through track

services-factory

Services and factories

Last reviewed May 28, 2026 Content v20260528
Track mode
client_angularjs
Means
In-browser AngularJS 1.x
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Services and factories: the concepts, APIs, and habits you need before advancing in AngularJS.

Without Services and factories, you will struggle to read or extend AngularJS codebases and playground exercises.

You will apply Services and factories in contexts like: Singleton services hold shared state and API clients across controllers.

Write JavaScript for AngularJS 1.8, click Run—register modules/controllers, then mountApp(moduleName, templateHtml) in #ng-app; printOutput feeds the terminal.

When you can explain the previous lesson's ideas without copying starter code.

Services, factories, and providers register singletons for API access and shared state.

Important interview questions and answers

  1. Q: Why does this matter?
    A: Services, factories, and providers register singletons for API access and shared state.

Self-check

  1. Summarize Services and factories in one sentence.
  2. What would you try next in the playground?

Challenge

Services and factories hands-on

  1. Edit the default code.
  2. Click Run in browser.
  3. Confirm preview or terminal output.

Done when: preview or terminal matches the lesson goal.

Challenge

Increment shared service

  1. Click + and confirm terminal JSON increments.
  2. Reload and verify service state resets (no persistence).

Done when: terminal count increases on each click.

Interview prep

Service vs factory?

service() invokes constructor with new; factory() returns the object/function you register—both are singletons per injector.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs in your browser in a sandboxed frame. Backend runners appear when this track’s profile allows them.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Service vs factory?
  • Singleton pattern?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump