The @Attribute
decorator returns the value of the specified attribute that attached to the selector.In some cases, This can bring a performance boost to the application.
Suppose we are having a static value, that we need to child component, we mite use @input
. By doing this we are attaching some event and on every change detection cycle it will check for changes.This can affect the performance as this is static value.
For solving this issue we can use @Attribute decorator which will take value only once.Keep in mind that we won't able to pass variable, it should be passed as string.
We will inject this decorator as in the code below in the child component.
With this changes, Angular will evaluate it once.
So this is what I understandings about @Attribute decorators. If anyone else have any extra information you can comment.
keep learning.
Top comments (1)
Great explanation