如何區分 Rs 和 % 值? (How to differentiate Rs and % values?)


問題描述

如何區分 Rs 和 % 值? (How to differentiate Rs and % values?)

在我的購物車應用程序中,我從服務器獲取價格和百分比報價。我需要用盧比區分價格值和百分比值。和 %。

這是我在控制器中的代碼:

if(result.type == 'Price'){                                     
                                    $scope.invoice_amt = $scope.invoice_amt ‑ result.offer ;                                                                                    
                                    } 
                                    else if(result.type == 'Percentage'){                                     
                                    $scope.invoice_amt = $scope.invoice_amt * result.offer/100;                                                                                    
                                    } 

我在 HTML 中將值設為 {{invoice_amt}} 如何在 rs 中顯示優惠。和百分比。


參考解法

方法 1:

You have to use currency filter, this below sample will print in Rupees ( ₹ )

   Invoice Price<span>{{invoice_amt | currency:"&#8377;"}}</span>

Percentage related point is mentioned in below link

Angular calculate percentage in the html

Use one more variable in your scope to check the type and based on that write the logic. Refer the Angular documentation https://docs.angularjs.org/api/ng/filter/currency

(by Vigneshkudlatiger)

參考文件

  1. How to differentiate Rs and % values? (CC BY‑SA 2.5/3.0/4.0)

#ng-repeat #shopping-cart #angularjs #logic






相關問題

ng-repeat 加載後不顯示表行 (ng-repeat not showing table rows after loading)

僅在 ng-repeat 中將 ng-if 應用於所選項目 (Apply ng-if in ng-repeat only to selected item)

AngularJS:獲取複雜過濾數組的大小 (AngularJS: Get size of complex filtered array)

單擊時更改 ng-class(嵌套 ng-repeat) (Changing ng-class when clicked (nested ng-repeat))

帶有選擇/選項下拉框的嵌套 ng-repeat 問題 (Nested ng-repeat issue with select/options drop down box)

錯誤:[ngRepeat:dupes] 不允許在轉發器中重複。使用“track by”表達式指定唯一鍵 (Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys)

在 AngularJS 中保存在 ng-repeat 中生成的字段 (Saving a field generated in ng-repeat in AngularJS)

遍歷對像數組以構建 div 結構 (Iterate over array of object to build a div structure)

ng-repeat 中 IE 下拉列表中的 Angularjs 無法正確呈現 (Angularjs in IE dropdowns in ng-repeat do not render correctly)

動態 ng-repeat 表單的優雅解決方案 (Elegant solution for a dynamic ng-repeat form)

如何區分 Rs 和 % 值? (How to differentiate Rs and % values?)

難以為一組對象運行 ng-repeat (difficulty running ng-repeat for an array of objects)







留言討論