Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Few questions about directives
Message
De
22/03/2015 05:18:19
 
 
Information générale
Forum:
Javascript
Catégorie:
Autre
Divers
Thread ID:
01615790
Message ID:
01617080
Vues:
39
This message has been marked as a message which has helped to the initial question of the thread.
>>>>>>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.....
>>>>>
>>>>>There is some activity in the issue I raised
>>>>>
>>>>>https://github.com/angular/angular.js/issues/11157#issuecomment-75706528
>>>>>
>>>>>and I also posted a new plnkr
>>>>>
>>>>>http://plnkr.co/edit/z1BWMoPmnsCZlAUra0os?p=preview
>>>>
>>>>Using Priority and push gives exactly the same formatter execution order (ie angulars directive followed by yours). Behaviour is the same in both cases.
>>>>What exactly is your problem with this code ?
>>>>BTW you should probably also add 'event.preventDefault()' in your keydown event handler - simply returning true/false only works in IE.
>>>>
>>>>Also you need to prevent multiple decimal points:
if (isDecimal(event.keyCode)) {
>>>>                          if (event.srcElement.value.indexOf('.') !== -1) {
>>>>                              event.preventDefault();
>>>>                              return false;
>>>>                          }
>>>>                      }
(or use a regex)
>>>
>>>Thanks, I'll make adjustements.
>>
>>But you didn't answer my question: "What exactly is your problem with this code ?"
>
>I was seeing the error that I posted in the issue, but I do not seem to reproduce it in that plnkr. Also, I do not see the number formatted with , e.g. I thought the idea of the directive was to nicely format the number to be 890,900.00 (e.g. with commas), but I do not see that in the directive's code or the output.

There's nothing in your directive to add commas (and if there was I don't think it would display if type=number). If it's currency then get rid of the type=number (you're filtering input anyway) and then:
return newValue.toLocaleString('en', { style: 'currency', currency: 'USD' });
Or angular:
return $filter('currency')(newValue);
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform