How to format currency like kendo ui 's template using angularjs - angularjs

I want to get this format In USD : 1.123.362,32 and this format in euro :1,122,363.33
I used AngularJS Filter "currency" who Format a number to a currency format but without separtors like "," "."

Use a Filter
here is a link to the docs where you can see an example.
You need to use the currency filter to get the desired effect. It should look like this
HTML
{{ currency_expression | currency : symbol : fractionSize}}
JS
$filter('currency')(amount, symbol, fractionSize)
To do this with the correct , or . you need to have the correct currency format selected.
Math.round()
inside your controller when you are setting the scope make sure you do Math.round() so the number you return is always whole.
Example
Math.round(2.5);
Alternatively
If the currency filter does not meet your requirements you can always use the number format that Angular provides, Doc are here
HTML
{{ number_expression | number : fractionSize}}
JS
$filter('number')(number, fractionSize)
If All Else Fails
Create your own custom filter here is a tutorial on how to build your own custom filter in angular, since your requirements are a little strange you should consider building your own filter to match them. This way you can set your , or . and anything that precedes or follows your number.
Its definitely more difficult than using the built in functionality but since you cant get it to match up with either of the methods above I would take this route.

currency angularjs's filter does not deal comma in usd and point in euro.... I used kendo ui like the filter in grid,it deal all event :
kendo.toString(236, 'c', fr-FR);
hope we find a complete solution with angularjs.

Related

angular: uib-datepicker locale is not set dynamically

Consider the following setup: I have a form with a angular-bootstrap datepicker (uib-datepicker-directive), which I want to serve with different languages, such that dates are shown in different formats.
I am changing the locale dynamically with the angular-dynamic-locale-module, by using information from the state parameters.
A date object is printed with correct language-specific format using the angular date filter: {{vm.date | date:'fullDate'}}
Unfortunately the formatting for the datepicker is not working immediately. When loading the page and call a set-locale function it needs a click into the datepicker to adjust the format of the month and click to the month and back to additionally adjust the translations for the weekdays.
I have created a plunkr to demonstrate the behaviour.
http://plnkr.co/edit/2HA8LI5SzUqx2jSmUdjn?p=preview
Does anyone know this behaviour? And if so, is there a way to fix this, preferably without messing up the datepicker directive?
Thanx in advance, micoud

Stop Angular from listing all from database?

I have a simple Angular Script which works like ajax to return search results, but when I don't type anything into the search box, it lists all of the data in the data base, how do I stop this?
My script is here: http://www.elliottcoe.com/search/search.js
instead of just validating with null check for empty string
if($scope.keywords==null || $scope.keywords.trim()==""){
$scope.trustedExample = $sce.trustAsHtml("<p>Please enter some text in search field</p>");
}
You can use a built in filter limitTo: <Any Limitation Number>
limitTo docs

Filter and replace an attribute name with Angular JS

I have this JSON:
{name:attr:MyDescription, value:TEST_DESCRIPTION}
{name:attr:MyVersion, value:TEST_VERSION}
I need to print the value of "name" attribute without the "attr:" prefix.
I want to print "MyDescription" and "MyVersion" and not "attr:MyDescription" & "attr:MyVersion".
I've wrote a filter and I've tried to result the single element with item.name.replace('attr:','') but it doesn't work.
Is there a way to handle this kind of situation with Angular JS?

Angular JS formate date

Is there any directive in Angular, I want to enable user when he write 2/3/67 in input for date date needs to be formatted like 02/03/1967 I tried few things on my own but they didn't work.
Just add a Angularjs formating, when displaying users input like so
{{yourdate.variable | date:'yyyy-MM-dd'}}
Se more at AnguarJS date function
EDIT
Here is working Plunker, with different type of dates. Enjoy

Is it possible to use multiple lines in Angular attributes?

Is is possible to include a newline in an Angular JS expression in an attribute tag? Something like this:
<p ng-repeat="
foo in foos
| filter:{attr: 'something really long'}
| orderBy:bar">
{{foo}}
</p>
EDIT: To clarify, the above doesn't work. I was wondering if there is some other syntax that allows for breaking this kind of expressions into multiple lines.
angular.js parser would be able to handle it, but there's a quick regex check before handing it to the parser (see http://docs.angularjs.org/error/ngRepeat:iexp):
Be aware, the ngRepeat directive parses the expression using a regex
before sending collection and optionally id to the AngularJS parser.
This error comes from the regex parsing.
I filed a bug to loosen this restriction: https://github.com/angular/angular.js/issues/5537, you can hand-patch it in the meantime, it's just 1 character: m (/regex/m).
It is possible for an expressions to span multiple lines. But ng-repeat throws an error if you try to span the expression on multiple lines.
Take a look at this plunker:
Add a new line in the ng-repeat expression and open the browser console to see the error message.
http://plnkr.co/edit/E1O8Iy3VzL3kzj72BDUL?p=preview
Yes, it is possible to use multiline attributes with ANY HTML element, including AngularJS directives.

Resources