Exploring the Various Decorators in Angular – NetanelBasal

  • QueryList implements an iterable interface it can be used in Angular templates with the ngFor directive.
  • The QueryList is initialized only before the ngAfterViewInit lifecycle hook is available only from this point.
  • Returns the specified elements or directives from the view DOM as QueryList
  • If the injector does not find the dependency, it will throw.
  • The @Host decorator tells DI to look for a dependency in any injector until it reaches the host

QueryList is just a fancy name for an object that stores a list of items. What is special about this object is when the state of the application changes Angular will automatically update the object…

@JavaScriptKicks: Exploring the Various Decorators in Angular by NetanelBasal #javascript #angularjs via JavaScriptKicks

@Attribute —

Returns the value of the specified attribute from the host

@ViewChildren—

is just a fancy name for an object that stores a list of items. What is special about this object is when the state of the application changes Angular will automatically update the object items for you.

directive. ( you can read more about this topic here )

Getters —

decorator will return the component instance, but you can ask for other tokens:

@ViewChildren(AlertComponent, { read: ViewContainerRef }) alerts: QueryList

You can see that you also can use a local variable from your template to get a reference to the element in your parent component.

to our host because when you don’t provide a parameter the class property name is used.

The @Self decorator tells DI to look for a dependency only from itself, so it will not walk up the tree

If the injector does not find the dependency, it will throw.

If the injector does not find the dependency, it will throw.

For a more complicated use case you can read my article — Angular — Clean Up your Form Template.

provider in any injector.

Let’s Angular know that a class can be used with the DI

Remember that this decorator is not required if the class does not have any dependencies or you don’t need the class to be injectable.

Exploring the Various Decorators in Angular – NetanelBasal