A quick tip for reacting to @Input changes in Angular

preview_player
Показать описание

In this video, we take a look at how to use setters to automatically run some logic when an input to an Angular component changes.

0:00 Introduction
0:54 ngOnChanges
1:27 Getters/Setters
2:29 Using Setters with @Input

#ionic #angular #reactive

Рекомендации по теме
Комментарии
Автор

It has its own limits. I had just fix someone's code that used setters on multiple inputs, and it blew out of control. Those setters were fired up individually before all other code without knowing if other inputs setter were fired or not so half of the properties were undefined.
OK nice for a a single input but for complicated components with multiple inputs the ngOnChanges is you saviour

marusak
Автор

Had no idea you could do that with an input. Thanks for sharing.

snowtranslation
Автор

one of the greates channels you have a great way of explaining things 👍🏻 helped me out a few times now 😁
thank you for the effort joshua 👏🏼👏🏼👏🏼

message
Автор

What I thought of recently that you could maybe cover are common Design patterns and how they would translate to Angular. For example the observer pattern is already solved with rxjs but there are many more. I have looked it up before but only seen them in written form and not in a video format which could be interesting.

LuckystrikeGFXer
Автор

That's a nice method indeed, a little less verbose than onChanges 🙂 Thanks for sharing !

AlainBoudard
Автор

excellent trick, thanks for sharing, so I suppose performance is much better than using inputs.

adamojordanfigueroa
Автор

Very interesting. Is there a benefit to doing it this way over using ngOnChanges? I feel like having this type of logic at the top of the class could get messy and not be as clear as handling it within ngOnChanges.

steven_bkk
Автор

Hey, i always have this confusion.. what is the best practice. Is it by using ngOnchange method or by using set method on input(like you showed in the example)

sridhar-natuva