繁体   English   中英

如何在“`title`”标签内调用这个“`ng-bind-html`”?

[英]How to call this "`ng-bind-html`" inside "`title`" tag?

我正在尝试在“ title ”标签内使用“ ng-bind-html ”指令来呈现带有货币符号的货币值,但表达式未计算。

这就是我的方式:

$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

当我在<span>标记内显示时它工作正常,但我也想在<title>标记中显示相同的格式化值。

所以想知道如何在“ title ”标签中调用这个“ ng-bind-html ”来显示与<span>标签中相同的输出?

ng-bind-html是一个指令 花括号用于表达式。 不会从表达式中处理指令。

重写你的表达式如下:

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

并将您的currencySymbol值替换为货币前缀所需的字符串。 $scope.currencySymbol = "€ ";

这是一个工作 plunkr

有关货币过滤器的其他文档

表达式的相关文档

如果您真正专注于动态处理货币符号并将其视为 html,则需要编写一个接受 sceHtmlString 的自定义货币过滤器。 Javascript 字符串支持 unicode,因此您提供的用例似乎不需要这个。

试试这个,你可以给 div 添加标题。 但它不会是可见的,因为标题不是文本字段。

 <!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>

请使用ng-attr-title设置 html 元素的 title 属性:

<div ng-attr-title="{{yourValue}}">

<label ng-attr-title="{{'TEXT' | translate}}" title="&#8364;5">Name:</label>

使用条件设置标题属性并使用角度翻译

<li title="{{admin ? ('purchase.pack'|translate) : ''}}"><span translate>pack.details</span></li>

您可以使用上述方法在标题属性中添加货币符号。

请看一下是否可以在标题属性中添加html? 也。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM