Does precedence in attribute/event statements in Tags make a difference? Angular2+

Asked

Viewed 21 times

0

I work with Angularjs and Angular2+ almost two years ago and recently, in Angular2+, I came across a different situation that made me wonder if it was a coincidence or because of the version of Angular I’m using. But someone knows the reason or has already gone through this I report below?

Example:

ps: Attend ngModelChange and ngModel event

Declare an INPUT tag in the following order:

<input [(ngModel)]="valor.numero" (ngModelChange)="validarValor()"/>

Different from reversing the order of attributes:

<input (ngModelChange)="validarValor()" [(ngModel)]="valor.numero"/>

In the first situation, I can use the value.numero in the validationValue method normally, which I cannot do using the second situation because the value is not set yet.

Really the precedence of TAG attributes/events/parameters matter?

Stay there tbm the tip, in case someone is going through the problem I went through, because at first I was not able to manipulate the value, because it had not yet been set.

Thanks in advance!

1 answer

0

The order of attributes does not matter, they are part of the same array of attributes. What may be happening is that since the directives are with bind, it makes one attribute depend on the other. In your example run the method validarValor() after assigning the ngModel at the valor.numero.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.