IsmailS
IsmailS

Reputation: 10863

Setting value on array, it is not updating child component - Angular

I'm trying to prevent triplicate values and handling the logic in parent component. However, it successfully prevents 3rd value once, but not subsequent times. The problem is when setting value on array, it is not updating child component. I'm trying to understand why it is not behaving the same way on subsequent times...

Reproduces here

Upvotes: 1

Views: 591

Answers (1)

Murtaza A
Murtaza A

Reputation: 41

The problem is that there is no change in the Input property the second time onwards.

You are reassiging the same value (i.e., empty string literal oValues[oNumber] = '';) to the property in your array.

e.g. for oValues[3]

First change: Previous value = '2', new value = ' '

Here Angular change detection detects the change on the Input property.

Second change: Previous value = ' ', New value = ' '

Here Angular change detection does not detect a change in the value of the Input property.

So basically Angular change detection triggers only if it finds a change in the Input property's value.

Upvotes: 1

Related Questions