Is there a way to update a string variable when another variable changes? I have a string that is built by using various variables. I display that string in the component's html file using interpolation. However, if a variable changes that the string was using to build itself, the string will never change because they not mutable. Only way would be to reset the string again when one of the other variables change.
Sample ts code:
import { Component} from '@angular/core';
@Component({
    selector: 'app-test-component',
    templateUrl: './test.component.html',
    styleUrls: ['./test.component.scss']
})
export class TestComponent {
    myString = '';
    amount = 0;
    constructor() {
        this.myString = `Hello, you have ${this.amount} dollars.`;
        setTimeout(() => {
            this.amount = 40;
        }, 5000);
    }
}
Sample html code:
<p>{{ myString }}</p>
Of course, after five seconds, the string stays the same because I never reinitialized it. Is there a way to automatically detect if any of the variables being used inside myString change, then update myString to use the values of the changed variables?
Thank you, any information is appreciated!
this.amountwill be changing in various other parts of the code. I was just trying to give an example on what I'm trying to accomplish (when the amount changes,myStringstill has the original value fromamountas 0). I'm trying to prevent myself from updating the string in multiple places of the code and hoping there's a way wheremyStringcan detect which variables it is using and if any of the change, then update the string to hold the new value.