I have this code and it works fine:
<a [routerLink]="['/menuItemOne']">
<span [innerHTML]="(mystrings$ | async)?.menuItemOne | htmlToText"></span>
</a>
But now I need to update the page title when the link is clicked.
I added a setTitle method on the component:
public setTitle( newTitle: string) {
this.titleService.setTitle( newTitle );
}
Using (click) function I can update the page title and it works fine:
<a [routerLink]="['/menuItemOne']" (click)="setTitle('Menu Item One')">
<span [innerHTML]="(strings$ | async)?.menuItemOneStr | htmlToText"></span>
</a>
But how do I do it to pass the variable menuItemOneStr instead of using the string 'Menu Item One'?
I tried:
<a [routerLink]="['/menuItemOne']" (click)="setTitle((strings$ | async)?.menuItemOneStr | htmlToText)">
<span [innerHTML]="(strings$ | async)?.menuItemOneStr | htmlToText"></span>
</a>
But it doesn't work. Any ideas?
You can subscribe to it on your
setTitlemethodAnd in your HTML
This means your subscribing to it twice, since the
asyncpipe subscribes aswell. It seems like yourstrings$isObservable<object>[]so you can can usengForand subscribe once. This means yoursetTitlestays the same but the HTML is changed. As a note, you can use interpolation inside any tags with pipes using the{{ variableName | somePipe }}notation.Updated HTML