Precedence of attribute / event declarations in TAGs make a difference? Angular2 +

0

I've been working with AngularJs and Angular2 + for almost two years and recently, in Angular2 +, I came across a different situation that made me wonder if it was a coincidence or because of the Angular version I'm using. But does anyone know the reason or has it gone through what I report below?

Example:

ps: Attend to the event ngModelChange and ngModel

Declare an INPUT tag in the following order:

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

It's different than inverting the order of attributes:

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

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

Does the TAG attribute / event / parameter precedence really matter?

I'm not sure what to do,

Thank you in advance!

    
asked by anonymous 14.09.2018 / 20:26

1 answer

0

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

    
14.09.2018 / 21:41