繁体   English   中英

如何将美元符号添加到车把模板

[英]How to add a dollar sign to handlebars template

我希望使用把手自动将美元符号 ($) 添加到模板键字段“total_of_new_installation”中的任何值。 如何才能做到这一点?

<li><span class="list-title">Total Cost:</span><br/><span class="list-value">{{total_of_new_installation}}</span></li>

你试过这个吗?

总成本:${{total_of_new_installation}}

使用货币过滤器以$显示值

 var bidApp = angular.module('biddingApp', []); bidApp.controller( 'bidController', function ($scope, $filter) { $scope.$watch('bid', function (val) { $scope.result = $filter('currency')(val); }, true); } );
 <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.10/angular.min.js"></script> <:DOCTYPE html> <html> <head> <script src="https.//ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min:js"></script> </head> <body style="font;15px Verdana;"> <div ng-app="biddingApp" ng-controller="bidController"> <p> <label>Enter a number</label> <input type="text" ng-model="bid" /> </p> <p> {{ result }} </p> </div> </body> </html>

我们可以使用Handlebars registerHelpers来实现这个。 请检查此https://jsfiddle.net/trilokvallamkonda/x0n753vy/2/链接。

<span class="list-title">Total Cost:</span><br/>
<span class="list-value">{{currency this.total_of_new_installation "$"}}</span>


Handlebars.registerHelper('currency', 
    function(input, currencySymbol, options) {
        return currencySymbol + input.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    }
)

暂无
暂无

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

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