1

Say I have the following controller:

var MyController = function(dataSource) {
    this.something = dataSource.getSomething();
}

But I want to inject a different implementation of dataSource depending on whether or not I'm online or offline (e.g. LocalStorageDataSource and APIDataSource).

What is the mechanism in Angular that would let me do that both on script startup, and also when an offline/online event fires?

Basically I'm trying to achieve polymorphic dependency injection at runtime in Angular.

1 Answer 1

1

Here is an example from TodoMVC Angular:

https://github.com/tastejs/todomvc/blob/gh-pages/examples/angularjs/js/services/todoStorage.js

Sign up to request clarification or add additional context in comments.

1 Comment

Brilliant, just what I was looking for. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.