Ensure Angular JS includes a space or special character after applying a currency filter

Is there a way to include a space or special character after the "₹" symbol?

Desired output: ₹ 49

Current output: ₹49

HTML - {{cart.getTotalPrice() | currency:"₹"}}

Answer №1

Don't bother trying to achieve it with the currency filter. Just stick to using the number filter.

 <div ng-controller="MyCtrl">
            <input class="tb" ng-model="numberInput" type="text" />            {{ "₹  "+(numberInput | number:2) }}              
  </div>

DEMO

var app = angular.module("app", []);
app.controller('AddSiteURLCntr', function($scope, $sce) {
  $scope.numberInput = '1275.23';
   
})
<!DOCTYPE html>
<html>

<head>
  <script data-require="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="caaba4adbfa6abb8e4a0b98afbe4fee4fd">[email protected]</a>" data-semver="1.4.7" src="https://code.angularjs.org/1.4.7/angular.js"></script>
  <link rel="stylesheet" href="style.css" />
  <script src="script.js"></script>
</head>

<body ng-app='app'>
  <div ng-controller="AddSiteURLCntr">
      <input class="tb" ng-model="numberInput" type="text" />            {{ "₹  "+(numberInput | number:2) }}     
  </div>
</body>
</html>

Answer №2

Give this a shot

Check it out

<span ng-bind="displayPrice(cart.getTotalPrice())"></span>&nbsp;
<span ng-bind="extractCurrency(cart.getTotalPrice())"></span>

Handler

 $scope.displayPrice = function (item) {
    return ($filter('currency')(item,'$')).substring(0,1);
 }

 $scope.extractCurrency = function (item) {
    return ($filter('currency')(item,'$')).substring(1,item.length);
  }

Answer №3

<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
</head>
<body ng-app="my-unique-app">
<div ng-controller="my-custom-controller">
<input type="number" name="price" ng-model="totalPrice">
<p>{{getTotalPrice() | currency : "&#8377;  "}}</p>
</div>
<script type="text/javascript">
var customApp = angular.module("my-unique-app",[]);
customApp.controller("my-custom-controller",function($scope){
$scope.totalPrice = 0;
$scope.getTotalPrice = function(){
return $scope.totalPrice;
}
});

</script>
</body>
</html>

Answer №4

To achieve the desired output, simply add a space after each symbol.

Example - {{change.getPrice() | currency:"$ "}}

Follow this format and you will see the result you want...

Answer №5

If you want to customize the currency filter, you can create your own filter for handling money values...

angular.module('customModuleName').filter('moneyConverter', customFilter);

function customFilter($filter, $locale) {

  const formats = $locale.NUMBER_FORMATS;

  return function(amount, currencySymbol) {

    if (!currencySymbol) currencySymbol = formats.CURRENCY_SYM + ' ';

    return $filter('currency')(amount, currencySymbol);
  };
}

Once you have created your new filter named 'moneyConverter', you can utilize it in your code like this...

<span>{{vm.totalAmount | moneyConverter}}</span>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubleshooting material design CSS problem in AngularJS routing module

Attempting to incorporate material design with routing in angular js, but encountering issues with CSS design not working. Interestingly, when using bootstrap CSS, it functions properly. Check out the Plnker Demo here However, upon trying this approach, ...

Issue with Angular FormControl Pattern Validator failing to validate against regex pattern

My goal is to restrict a text input field to specific characters only. I am looking to allow: alphanumeric characters (a-z A-Z 0-9) 3 special characters (comma, dash, single quotation mark) : , - ' A few accented characters: à â ç è é ê î ô ...

Tips on how to implement dropdownlist filtering with angularJs based on the selection from another dropdownlist

There are two dropdown lists in my code: <div class="control-group"> @Html.LabelFor(x => x.ServiceId) @Html.DropDownListFor(x => x.ServiceId, new SelectList(Model.ServiceList, "Id", "Title"), new { @class = "open" }) &l ...

An error of type 'TypeError' has occurred, where it is unable to access the property 'render' of an undefined element in

I'm using a function in my controller to render the "result" in my "home-page" view, which is calling my model to execute the query. exports.searchNoms = (req, res) => { getDatabaseModel.searchNoms(req).then(function(result) { console.l ...

What's the best grid to use with Angular JS?

What is the top choice for displaying items in a table format using AngularJS? I have come across several options such as ng-table, ui-grid, ag-grid, and kendo-grid. I require functionalities like sorting, filtering, row styling, header column splitting, ...

Trouble with the navigation of the JavaScript image gallery: next and previous buttons are not

Is it possible to have multiple galleries on a single page with captions? I've been trying to incorporate this JavaScript code, but struggling to make the next/previous links function for both galleries. Since I'm new to JavaScript, any advice or ...

I need help figuring out how to represent a nested array within an array of objects within my data instance in Vue

Currently, I have a loop that is showcasing a list of items along with their respective sub-items. The data response payload for this operation appears like the following. I have successfully executed the loop and managed to display it on my frontend desi ...

Is innerHTML incapable of executing JavaScript code?

Experimenting with a new technique where I divide my code into separate files to create multiple HTML pages instead of one large one. Using ajax to load them and then setting the content as innerHTML to a parent div results in clean code that works well in ...

Is my Socket.io application consuming excessive bandwidth? What might be causing this issue?

Upon reviewing my AWS billing report, I noticed an excessive data transfer of 495.385 GB on my socket.io application running on the EC2 instance. This amount seems too high for a small experimental website like mine. Could this be due to inefficient code i ...

Switch the watch feature on and off using AngularJS

Is it possible to easily turn a watch on or off, or indicate whether the watch should be active right now? I am aware that I can unregister a watch, but how do I register it again? In my scenario, I have hierarchical select lists where changing the parent ...

Revolutionizing Form Select Field: Introducing Rails' Dynamic Input Rendering

I'm a beginner in coding, so please bear with me if my question sounds amateurish. Currently, I am developing an e-commerce website where customers can order posters from images uploaded to the site. They should be able to choose the size of the poste ...

Creating a personalized Material UI theme for enhancing the appearance of a Next.js App Router

Recently transitioned from C# development to diving into Next.js for a client project. Utilizing MUI, I have put in a day of work so far, resulting in a relatively small project. While I grasp the concept of SSR (Server-Side Rendering) theoretically, the ...

Traversing JSON data in a recursive manner without definite knowledge of its size or nesting levels

Currently, I'm working on a chrome app that utilizes local storage. The backend returns JSON data which I then save locally and encrypt all the items within the JSON. I have multiple sets of JSON with different encryption functions for each set. I at ...

A guide on creating a Utility function that retrieves all elements in an array starting from the third element

I've been working on a tool to extract elements from an array starting after the first 2 elements. Although I attempted it this way, I keep getting undefined as the result. // ARRAYS var arr = ['one', 'two', 'three', &a ...

Divide an HTML file into separate documents upon submitting a form

Is there a way to input HTML into a text area, then upon submission, have the system read the file, identify the class selector, and separate the HTML into multiple files saved in a directory? If you have any thoughts on how this could be accomplished, pl ...

JavaScript program that continuously reads and retrieves the most recent data from a dynamically updating JSON file at regular intervals of every few seconds

I am a beginner in JavaScript and I'm facing an issue with displaying the most recent values from a .json file on an HTML page. The file is updated every 10 seconds, and I am also reading it every 10 seconds, but I'm not getting the latest data. ...

I keep encountering an attach() error every time I try to close a modal that contains a vee-validated form

Every time I try to close a bootstrap modal (using bootstrap-vue) that includes a vee-validated "update" form with vue.js, I encounter the following error: main.js:477686 Uncaught (in promise) Error: [vee-validate] Validating a non-existent field: "#35". ...

Creating a structure object in a Laravel controller for implementing Vue.js autocomplete functionality

I am currently facing an issue with my autocomplete feature not displaying options correctly. To start off, I am fetching hard coded data from my controller and passing it through an axios call: searchController.php $searchResults = [ 0 => (ob ...

How to update data in AngularJS grid component using ng-bind directive

As a newcomer to AngularJS, I'm facing an issue that I need help with. Here's my problem: I have an ng-grid connected to a table. Inside the grid, there are values along with an ID (which is a foreign key from another table). Instead of display ...

How can I make the top two divs stay fixed as I scroll down, and then reset back to their initial position when scrolled

Hey there, I'm looking to have a div stay fixed after scrolling within its parent div. <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12"> <div class="fw ofndr-box"> <div class="ofndr-box-half add-here"> <a href="#! ...