Created
          September 23, 2013 07:25 
        
      - 
      
- 
        Save kohgpat/6667400 to your computer and use it in GitHub Desktop. 
    angular.js currency filter using accounting.js
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | angular.module("app.users", ["ngResource"]).factory("Users", function($resource) { | |
| return $resource("users.json", {}, {get: {method: "GET", isArray: true}}); | |
| }); | |
| angular.module("app.filters", []).filter("currency", function() { | |
| return function(number, currencyCode) { | |
| var currency = { | |
| USD: "$", | |
| RUB: "" | |
| }, | |
| thousand, decimal, format; | |
| if ($.inArray(currencyCode, ["USD", "RUB"]) >= 0) { | |
| thousand = " "; | |
| decimal = "."; | |
| format = "%s%v"; | |
| } | |
| else { | |
| thousand = "."; | |
| decimal = ","; | |
| format = "%s%v"; | |
| }; | |
| return accounting.formatMoney(number, currency[currencyCode], 2, thousand, decimal, format); | |
| }; | |
| }); | |
| angular.module("app", ["app.users", "app.filters"]); | |
| function UsersController($scope, Users) { | |
| $scope.users = Users.get(); | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <!doctype html> | |
| <html lang="ru" ng-app="app"> | |
| <head> | |
| <title>Angular: Filters</title> | |
| <meta chartset="utf-8"> | |
| <script type="text/javascript" src="src/js/jquery.min.js"></script> | |
| <script type="text/javascript" src="src/js/angular.min.js"></script> | |
| <script type="text/javascript" src="src/js/angular-resource.min.js"></script> | |
| <script type="text/javascript" src="src/js/accounting.min.js"></script> | |
| <script type="text/javascript" src="src/js/app.js"></script> | |
| <link type="text/css" rel="stylesheet" href="src/css/app.css"></link> | |
| </head> | |
| <body> | |
| <div id="container" ng-controller="UsersController"> | |
| <h1>Users</h1> | |
| <div id="filter"> | |
| <input type="text" ng-model="userFilter.firstName" placeholder="First Name" /> | |
| <input type="text" ng-model="userFilter.lastName" placeholder="Last Name" /> | |
| <input type="text" ng-model="userFilter.email" placeholder="Email" /> | |
| <input type="text" ng-model="userFilter.income" placeholder="Income" /> | |
| </div> | |
| <table class="table"> | |
| <thead> | |
| <tr> | |
| <th>First Name</th> | |
| <th>Last Name</th> | |
| <th>Email</th> | |
| <th>Income</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| <tr ng-repeat="user in users | filter: userFilter"> | |
| <td>{{user.firstName}}</td> | |
| <td>{{user.lastName}}</td> | |
| <td>{{user.email}}</td> | |
| <td>{{user.income | currency: "RUB"}}</td> | |
| </tr> | |
| </tbody> | |
| </table> | |
| </div> | |
| </body> | |
| </html> | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | [ | |
| { | |
| "firstName": "John", | |
| "lastName": "Doe", | |
| "email": "[email protected]", | |
| "income": "101720240.82" | |
| }, | |
| { | |
| "firstName": "Alice", | |
| "lastName": "Appleseed", | |
| "email": "[email protected]", | |
| "income": "100444331.65" | |
| } | |
| ] | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
http://blog.cloudcitydevelopment.com/2013/05/15/angular-js-accounting-js-and-currency/