HelloWorld
HelloWorld

Reputation: 4882

angularjs factories seem to be created lazily

Today I am experiencing something really odd which I have never read about.

Just think the debugger is on the "var startDateOfWeek..." line.

With my mouse pointer I hover over the wizardDataFactory object. This object is not instantiated when there is not the line of code "var x = ..." which comes later...

WHY is that? I have never read something about factories are somehow lazily instantiated?

Well I do not want to complain because actually thats a good thing. Do not instantiate when the factory is unused in code.

Can someone please share a link where I can read about that?

   'use strict';
    angular.module('iplanmylessons').service('periodService', function ($q, $http, datetimeFactory, weeklyDataGridViewModelFactory, wizardDataFactory) {

        this.getWeeklyPeriods = function (schoolyearId, firstDayOfWeek) {

            var startDateOfWeek = datetimeFactory.getFirstDateOfWeek(firstDayOfWeek);
            var endDateOfWeek = datetimeFactory.getLastDateOfWeek(firstDayOfWeek);

            var x = wizardDataFactory.transform();


            return [];
        };
    });

Upvotes: 0

Views: 28

Answers (1)

Code Whisperer
Code Whisperer

Reputation: 23652

Your understanding is not correct.

wizardDataFactory is initialized as soon as any other component requests it as a dependency.

The hovering undefined is probably due to a browser error.

Upvotes: 3

Related Questions