I am trying to emphasize a particular part of a text in Angular but only the dynamic part of the string. I have tried adding html elements in various places but that did not help. I am hoping I do not need to create a whole other component just to get the text make it bold an push it down to the other component that actually reads it.
In the HTML file:
<button mat-icon-button (click)="openThatThing()" matTooltip="Do the thing">
<mat-icon>some-icon</mat-icon>
</button>
In the TS file:
openThatThing(): void {
this.action = thing.that.needs.done;
const messageBody = "Do this to "" + this.current.name + ""?";
const thisThing = this.dialog.open(ActionDialogComponent, {
width: '400px',
disableClose: true,
hasBackdrop: false,
panelClass: ["something", "mat-typography"],
data: {title: "Confirm Thing", msgBody: messageBody, primaryAction: "Action"}
});
}
I would like this.current.name
to be bold. I can’t seem to find documentation or other stackoverflow articles on this particular matter. It is possible that I am not asking the question properly in the search engines.
2
Answers
I focused on the
ActionDialogueComponent
and from there I realized I could split outthis.current.name
from the string. Manipulate it however I wanted and stick it all back together in the aforementioned component's HTML file.You can style your text with HTML, for that you need to inject your HTML in ActionDialogComponent:
when you pass your msgBody you need to sanitize the HTML for security reasons:
if you know what
this.current.name
can be, you can trust the HTML with no problem.