[英]How to use exported function in another component in html? ANgular?
我已將 function 導出到單獨的文件中
export function sum(population): string {
return population.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
}
我在我的組件中導入這個 function:
import { sum } from '../../shared/utilities/globalFunction'
以及如何在 html 中使用這個總和?
當我設置
<p> {{ sum(variable-with-data) }}
沒有工作...
在 html 中只能在 ts 中使用“變量”公共,所以你需要聲明一個“變量”(*)並使用一些類似
//in .ts
mysum=sum
//in .html
{{mysum(variable-with-data)}}
就像另一個一樣,你不能使用 Math in.html 但你可以使用
//in .ts
myMath=Math
//in .html
{{myMat.cos(3.4)}}
(*) 我說變量,但可以是 class、object 和 function...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.