There are numerous versions of this question, many containing excessive and irrelevant details. Take into consideration the following scenario in a globals.ts file
interestingString:string = 'blah';
now in a neighboring component neighbor.ts file
displayMsg:string = this.formatInterestingStrs(this.globals.interestingString);
formatInterestingStrs(val:string) {
return val.substr(0, 21) + "...";
}
and in the HTML...
<div> here's the first 21 characters of something intriguing: {{displayMsg}} </div>
lastly... any other component can change the string at any point in time...
this.globals.interestingString = "I saw Cher in real life today! Man, did she dish on Greg Allman!"
I COULD address this by coding the HTML like so...
<div> here's the first 21 characters of something interesting: {{this.formatInterestingStrs(this.globals.interestingString)}} </div>
...however, this impacts performance. What I would prefer is to be able to "easily" make the globals variable observable or published when modified AND have every instance of it subscribe to the changes and THEN invoke a function to handle any additional alterations that rely on its value. Something equivalent in the globals...
PublishUpdates(interestingString:string = 'blah');
and in the module...
SubscribeToUpdates(this.globals.interestingString).thenDoThis(result){
this.displayMsg = this.formatInterestingStrs(result);
}
...and I'd like to achieve this without adding excessive bulk or numerous extra lines of code and procedures. Any suggestions?