What is the proper way to reference "ng-bind-html" within a "title" element?

I have been attempting to utilize the "ng-bind-html" directive within the "title" tag in order to display a currency value with its corresponding currency symbol, but unfortunately the expression is not being evaluated.

This is the approach I'm taking:

$scope.salary = 10000;
$scope.currencySymbol = '€';//€
<div title="{{ng-bind-html= 'salary |currency:(currencySymbol+' '): 0'}}"> //This is not working
<span ng-bind-html="salary |currency:(currencySymbol+' '): 0"> </span> //working fine and renders €10000

It works perfectly when displayed within a <span> tag, however I would like to also present the same formatted value within a <title> tag.

As a result, I'm left wondering how I can implement the use of the "ng-bind-html" directive within the "title" tag to achieve the same output as seen in the <span> tag?

Answer №1

ng-bind-html serves as a directive. Instead of using curly braces for expressions, a directive should be used separately.

To modify your expression, follow this format:

<div title="{{ salary | currency:currencySymbol: 0}}"></div>

Be sure to substitute the currencySymbol value with your desired currency prefix string. For example, set

$scope.currencySymbol = "€ ";

View a functional plunkr here

Find more information about the currency filter here

Explore related documentation on expressions here

If you absolutely need to process your currency symbol dynamically and treat it as html, consider creating a custom currency filter that accepts an sceHtmlString. Since Javascript strings support unicode, it seems that specialized functionality may not be necessary in this particular scenario.

Answer №2

Here is a suggestion for you: You can include a title within the div element, but keep in mind that it will not be visible since the title attribute does not display as text.

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular-sanitize.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">

<div ng-bind-html="myText"></div>
 <span>Currency Example:</span>
      <div> {{ salary | currency:currencySymbol: 0}} </div>
       <div title=" {{ salary | currency:currencySymbol: 0}}"> nodata</div>
     <span>Currency Example ng-bindhtml</span>
     <span ng-bind-html="myText"></span>
     <p ng-bind-html="myText"></p>
    </div>
</div>

<script>
var app = angular.module("myApp", ['ngSanitize']);
app.controller("myCtrl", function($scope) {
    $scope.myText = "My name is: <h1>  111 John Doe</h1>";
     $scope.salary = 10000;
   $scope.salaryhtml = "<p> €10000 </p>";
  $scope.currencySymbol = "€";
  $scope.myText ="  <h1>$ 1000 </h1>";
});
</script>



</body>
</html>

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

The delay function in jquery is not functioning as expected

Hey everyone, I'm having trouble with my timing function in the code below... $( document ).ready(function() { $.ajax({ type: 'GET', url: 'conversation.json', dataType: 'json', success ...

Show off a sleek slider within a Bootstrap dropdown menu

Is there a way to display a sleek slider within a Bootstrap dropdown element? The issue arises when the slider fails to function if the dropdown is not open from the start, and the prev/next buttons do not respond correctly. For reference, here is my curr ...

The presence of parentheses in a JQuery selector

My database contains divs with ids that sometimes have parentheses in them. This is causing issues with my JQuery selector. How can I resolve this problem? Let me provide an example to illustrate: https://jsfiddle.net/2uL7s3ts/1/ var element = 'hel ...

Fade all list items other than the one that is selected

I have a group of items in a list. Whenever you click on an item, it expands to show more information. I would like all other items in the list to be blurred except for the one that is expanded. <li href="#" class="list-group-item" ng-repeat="task in t ...

What is the process for installing a third-party library in React Native without using npm or yarn?

Is there a way for me to install a third-party library manually without affecting the build run or performance of my project? I am looking to add this specific library: https://github.com/asmadsen/react-native-unity-view ...

Accessing Json Data Using AngularJS User Authentication

Currently, I am in the process of developing a user login page that stores user information in a json file. I have successfully created the GET method for accessing the file, but I am facing difficulty in redirecting the user after a successful login. Any ...

The server gets blocked by numerous AJAX GET requests happening at the same time until the data gets returned

In my Rails application, I am using the gridList library to display charts. The chart data is fetched asynchronously from a controller method in JSON format via AJAX. Upon initial page load, each gridlist item displays a loading icon while simultaneously m ...

Show User Input as a dynamic tool-tip in Highcharts

Is it possible to gather 12 user inputs through multiple text areas in a popup dialog box, and then use these inputs as tooltips for various points on a graph like the one shown in this demo: http://www.highcharts.com/demo/line-labels? I haven't found ...

Error message: "Unable to find reference process. simple-peer Javascript"

Currently, I am delving into WebRTC and utilizing simple-peer, an npm package, with React and Socket.io. However, whenever I attempt to make a call, I encounter this error: _stream_readable.js:529 Uncaught ReferenceError: process is not defined at emit ...

How can I use an array to dynamically populate an option html tag in react?

I am attempting to populate an option in jsx with values from an array called currencyOptions. Despite using this method, the options are remaining blank. The array is passed down to the component as a prop, set using useState, and the data is fetched from ...

What is the best way to specify a function parameter as the `QUnit` type using TypeScript in conjunction with QUnit?

In my project, which is partially written in TypeScript and licensed under MIT, I am utilizing QUnit. I have some TypeScript functions that require QUnit as a parameter, and I would like to define their types based on its interface from the typings. For e ...

Effective Ways to Reveal a Navigation Tab within Ajax's Jquery Success Function

In my index.php file, I have three nav-tabs. Two of the tabs can be accessed directly by clicking on them, but the middle tab requires the user to enter a PIN for authentication. The issue I'm facing is that the Admin-tab in the middle only shows onc ...

Order verification through the browser's geolocation API

How does the Geolocation Browser API detect a visitor's location? According to the W3C Geolocation info site, the API utilizes a combination of IP, Wi-Fi, Cell-Phone, and GPS to determine a user's location, but it is not specified in what order ...

Top method for concealing image within adaptable block

I am currently working on making the header slideshow responsive. I encountered an issue where I couldn't use the CSS property background with cover. Instead, I need to utilize <img> inside a div. <div class="parent"> <img src="slide ...

Restrict the number of times jQuery runs when hovering over an element

I recently developed a hover menu with CSS and jQuery to display sub-menus. However, I noticed that if the user hovers multiple times on the menu item, it behaves strangely. You can check out the menu in action at this URL: . Here's the jQuery code I ...

Controlling the Class Attribute in a <td> Element with JavaScript Upon Click Event

I am currently grappling with a situation involving a table with 5 <td> elements. By default, these <td> are red in color. If the user clicks on one of them for the first time, it changes to blue. Subsequent clicks turn it orange and then back ...

Using JavaScript to Create Dynamic Variable Names - Multiple Arrays?

In my project, I am working on creating markers for each user in my loop. These markers need to be generated in a way that allows me to later select them based on the corresponding userId. $.each($.parseJSON(window.usersArray), function (i, user) { w ...

Enhancing code readability in vim with custom Javascript syntax highlighting

Is anyone else experiencing issues with VIM's syntax highlighting for Javascript? I have noticed that at times, the highlighting seems to disappear and I have to scroll around to get it adjusted properly. Does anyone know of any workarounds or soluti ...

Launching Toasts with Bootstrap 4

I've been working with toasts in Bootstrap 4 and one thing has been bothering me: When I initialize the toast like this: <div class="toast my-3" data-delay="2500"> <div class="toast-header text-dark"> //fill this later &l ...

The ng-if condition is never met

I am currently utilizing AngularJS in my project. <div ng-repeat="l in kites"> <a ng-click="findit(l.green.num)">color</a> <span ng-if="c_{{l.green.num}} == 'y'>kites is </span> </div> Within my c ...