Instructor: Consider our logger service here, which we define in this ECMAScript class, which we use for logging out some messages. It's a bit more complicated.
For instance, it takes some configuration data, which could be isEnabled, which is a Boolean, and which controls whether the logger should print out messages or not. If we save that, you can immediately see that our dependency injector complains. He says, "There's no provider defined for Boolean," so he basically is not able to resolve this constructor argument here.
That's exactly where we can use a factory function. The factory function is defined as follows. First of all, we define that provider where we say, whenever there is the logger service injected to some constructor, use a factory. The factory -- let's call it logger factory -- is the function which we define up here.
This is a simple function, which then constructs our logger service here manually. As you can see here, we now have full control over how that object is being created. In fact, this way it still works. If we switch this to false, then you can see that, if we click the button, it does not work anymore.
Suppose this variable here is not something static, but it comes from some environment configuration. It makes already a lot more sense.