2
votes

In the tutorial 4 of angular dart, we build a simple Decorator. The decorator has a property that is bound with the usual @NgOneWay annotation.

But the decorator also has a constructor that takes a DOM element. In the tutorial example this is fundamental. Now how does the dependency injection of angular dart knows what to pass to constructor? It seems clear that the element passed will be the one the decorator is decorating. But how is this done?

When the module is declared in the main.dart there is a simple call to bind(), nothing more. Is there a clearer, more verbose way to bind the decorator constructor? Just for learning purposes, you understand.

1

1 Answers

3
votes

DI builds a hierarchy of injectors. For your element a new sub-injector is created. When your constructor requires an Element argument the injector starts looking in the current injector instance whether it can provide an instance that fits the type, if not it goes up the hierarchy until it finds an instance that is registered for the Element type of the root injector was reached without finding one, then an exception is thrown.