1

Hi I'm having doubt I'm using input signal instead of @Input I'm sending data from parent component one as simple variable like and another as signal

name = "ajai" name=signal("ajai")

Both are working what is the difference between these two statement. I thought input() is a signal it accepts only signal but it accepting normal string and effect also got triggered How ?

I would like to know which is best way to use name = "ajai" or name=signal("ajai") and when to use name = "ajai" or name=signal("ajai").

New contributor
Ajai Ramalingam is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

1 Answer 1

0

Signals:

name=signal("ajai") 
fullName = computed(() => (`Grand Master ${this.name()}`);

In the above example, the updates to name notify the consumers of name like fullName which is a state derived from the original state name.

So signals have the advantage that they are reactive, the changes to the actual values, trigger automatic updates on other reactive elements (computed, effect, resource, rxResource, linkedSignal) and make your code update only when it is actually needed and not all the time.

For best use of signals. Consider enable ChangeDetectionStrategy.OnPush so that change detection is not firing multiple times.


Normal Properties:

name = "ajai"

They can store values, but do not notify other blocks that use these variables for computations.

They are updated on each change detection cycle, note that updating these properties do not trigger change detection, but angular pre signals, fires change detection multiple times during an application lifecycle.

Not the answer you're looking for? Browse other questions tagged or ask your own question.