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

Using JQuery to extract information from a JSON file

Here is the code I am working on, where I pass input username and password values. The function I have written checks if the input matches the data in a JSON file. If there is a match, an alert saying "login correct" will be displayed, otherwise it will di ...

Retrieve the content from a textarea and insert it into a different textarea with additional text included

Users can input HTML codes into a textarea named txtar1. A 'generate' button is available; Upon clicking the 'generate' button, the content of txtar1 will be transfered to another textarea named txtar2 with additional CSS code. Here&ap ...

What is the most effective way to search for multiple queries in MongoDB based on the key passed in the request parameter?

When a get request calls this API, the search key is dynamically passed in via the id parameter. We are specifically looking for objects that have the Later_Today_P property set to true. Example MongoDB schema: { "user_logged_email" : "<a href=" ...

The onBlur() method is not functioning properly in JavaScript

Created a table using PHP where data is fetched from a MySQL database. One of the fields in the table is editable, and an onBlur listener was set up to send the edited data back to the MySQL table. However, the onBlur function doesn't seem to work as ...

Utilizing JFlex for efficient brace matching

Currently, I am in the process of developing an IntelliJ plugin. One of the key features that I am working on is a brace matcher. After completing the JetBrains plugin tutorial, I was able to get the brace matcher functioning using this regular expression ...

Error in React+Redux: Trying to access the "address" property of a null value is not permitted

I am new to using react and encountering an issue with my ecommerce app. The app runs smoothly until I log out and then log back in at the shipping address page, which triggers the following error: TypeError: Cannot read property 'address' of nu ...

Having trouble sending a POST request from my React frontend to the Node.js backend

My node.js portfolio page features a simple contact form that sends emails using the Sendgrid API. The details for the API request are stored in sendgridObj, which is then sent to my server at server.js via a POST request when the contact form is submitted ...

Is it possible for the server to initiate communication with the client

Every time I try to find a solution, Comet always comes up. But it seems like overkill for what I need - just around 100 users at most, with maybe 10 online simultaneously. Is there a simpler and more suitable option for my needs, such as pushing data to ...

Plugin for creating a navigation bar with a jQuery and Outlook-inspired style

Our team is considering transitioning our asp.net forms application to MVC. Currently, we utilize outlook-style navigation with ASP controls such as listview and accordion, using code referenced here. Are there any jQuery/CSS controls available for MVC t ...

In JavaScript, the act of shuffling an array will produce consistent results

I have created a random array generator by shuffling an initial array multiple times. SHUFFLE FUNCTION const shuffle =(array) => { let currentIndex = array.length, temporaryValue, randomIndex; while (0 !== currentIndex) { randomIndex = Ma ...

What is the process for inputting client-side data using a web service in ASP.NET?

Currently experimenting with this: This is my JavaScript code snippet: function insertVisitor() { var pageUrl = '<%=ResolveUrl("~/QuizEntry.asmx")%>' $.ajax({ type: "POST", url: pageUrl + "/inse ...

Resolving CORS issues: Troubleshooting communication between a React app and an Express server

After successfully running both the app and server locally, I encountered an issue upon deploying the express server. Whenever I try to make a request, I consistently receive the following error message: "has been blocked by CORS policy: Response to ...

Retrieve the properties of an object

I have a JavaScript program where I retrieve values from a JSON file and store them in an array. However, when I attempt to access the elements of this array, it returns nothing. Below is the function that pushes temperatures: temperatures = [] get_info ...

An addition operation in Javascript

Recently, I dipped my toes into the world of Javascript. However, I found myself puzzled by the script and its corresponding HTML output provided below. Script: <h1>JavaScript Variables</h1> <p id="demo"></p> <script> var ...

Ways to dynamically include onClick on a div in a react component based on certain conditions

Is it possible to conditionally set the onClick event on a div element in React based on the value of a property called canClick? Instead of directly checking this.state in the event handler, I am hoping to find a way to implement this logic within the re ...

What is the best method for directing a search URL with an embedded query string?

Currently, I am developing an express application that has two different GET URLs. The first URL retrieves all resources from the database but is protected by authentication and requires admin access. The second URL fetches resources based on a search para ...

Finding and retrieving specific information from nested arrays within a JSON object can be done by implementing a method that filters the data

I have an array of objects where each object contains a list of users. I need to be able to search for specific users without altering the existing structure. Check out the code on StackBlitz I've tried implementing this functionality, but it's ...

Separating stylesheets, head, and other elements in a curl response

After successfully using curl to retrieve an external site, I noticed that the results were interfering with my own content. The CSS from the external site was affecting my webpage's layout and z-index values were conflicting. I am seeking a solution ...

Utilizing v-model for dynamic binding within a v-for iteration

I'm currently working on binding v-model dynamically to an object property within an array of objects. I am unsure about how to accomplish this task. The objective is to choose a user using the Select HTML tag and then display the list of that user&ap ...

Guide on how to use a tooltip for a switch component in Material-UI with React

I am attempting to incorporate a tooltip around an interactive MUI switch button that changes dynamically with user input. Here is the code snippet I have implemented so far: import * as React from 'react'; import { styled } from '@mui/mater ...