简体   繁体   中英

Update the string value in the object based on the parameter - Typescript

I have exported an object in a separate ts file and I would like that to be parameterized

export const customer = {
  comment: 'Wow, this is great because {{username}} is doing what we needed' 
};

Then in another ts file, I get this constant but I want to pass the value of username

import * as customerConstants from 'constants';
export class CustomerComponent implements OnInit{
 username ='learn' 
 customerData = customerConstants.customer ;

  ngOnInit(): void {
    this.customerData.comment = customerData + username;
  }

I want to put learn in place of username in the customer const. Is it possible?

由于customer.comment是字符串,您可以使用replace()'{{username}}'替换为username变量值。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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