Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Few questions about directives
Message
De
26/02/2015 07:58:40
 
 
Information générale
Forum:
Javascript
Catégorie:
Autre
Divers
Thread ID:
01615790
Message ID:
01615859
Vues:
49
This message has been marked as the solution to the initial question of the thread.
>>>>But you really want your formatter to run *after* the angular formatter (so it can strip the commas that are present) and, since it will get it's value as a string it would need to be rewritten accordingly.
>>>>
>>>>UPDATE: I see it is expecting a string so forget the last bit.
>>>>
>>>>What I'm not sure about is how you ensure your formatter is second in the chain.....
>>>>
>>>>UPDATE2 : Duh. I now see that's what you were trying with negative priority. Did you check the actual order obtained in that case ?
>>>
>>>I am not exactly sure how to test. I could not find priority property anywhere.
>>>
>>>When I was debugging, I think I saw the formatter running first and then the InputNumber code, but I am getting confused.
>>
>>My logic is this:
>>
>>$formatters is an array of functions which are pipelined in reverse order.
>>You want angulars numberInputType formatter to run first, followed by your own smNumberFormat.
>>The two directives push their formatting methods into the array.
>>The order in which they are pushed depends on the priority order of the directive (higher numbers are compiled first)
>>The angular priority is 0.
>>So giving your directive priority *greater* than 0 should put your formatter first in the array and angulars second.
>>Since they are pipelined in reverse order that should give you the desired behaviour.
>>
>>So you want a priority > 0 for smNumberFormat
>>
>>UPDATE: Again I could be wrong. angular docs state the directives with a higher priority are compiled first but post-link functions are run in reverse order and I'm not sure what applies in this case. Maybe your directive *should* have a negative number.
>>
>>IAC, one or the other should work :-}
>
>I'll try now with positive priority, have nothing to lose anyway :)

I thought I'd posted something after this but anyway:

I tested using both positive and negative priority and your directive always ran first. I *did* get it to work by changing your formatter to:
                    function bind() {
                        return ngModel.$formatters.unshift(function (value) {
                            return format(value);
                        });
                    }
Don't know why the priority approach didn't work but this shows that your formatter needs to be first in the $formatters array.....
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform