我在單獨的 ts 檔案中匯出了一個物件,我希望將其引數化
export const customer = {
comment: 'Wow, this is great because {{username}} is doing what we needed'
};
然后在另一個 ts 檔案中,我得到了這個常量,但我想傳遞用戶名的值
import * as customerConstants from 'constants';
export class CustomerComponent implements OnInit{
username ='learn'
customerData = customerConstants.customer ;
ngOnInit(): void {
this.customerData.comment = customerData username;
}
我想在客戶常量中用學習代替用戶名。可能嗎?
uj5u.com熱心網友回復:
由于customer.comment是字串,您可以使用replace()替換'{{username}}'為username變數值。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/484013.html
標籤:javascript 有角度的 打字稿
上一篇:元素隱式具有“任何”型別,因為“數字”型別的運算式不能用于索引型別“{}”。.ts(7053)VUEJS
下一篇:驗證屬性存在的打字稿類吸氣劑
