I'm using a video series to get familiar with Angular, codewithmosh. He uses glyphicons in one of his exercises, but the video's from 2018. Glyphicon support seems to have been discontinued in bootstrap since then, but the bootstrap site still includes the html for their icons. I figured I would see if I could just do the same thing by pushing around raw html.
Problem is, the html pulled from component.ts is not rendering, and instead just shows the html code on the page. That same html in the component.html IS rendering.
I'm really new here so there could be an obvious flaw in my code. It's probably not pretty but it SEEMS sound, and I can't figure out why it's not working. Ideally this should be rendered as an empty star, which when clicked switches to the full star.
Thanks in advance for any help!
here's the app.component.ts:
import { Component } from '@angular/core';
@Component({
selector: 'app-star',
templateUrl: './star.component.html',
})
export class StarComponent {
isClicked: boolean;
fullStar: string = `
<svg (click)="onClick()" width="2em" height="2em" viewBox="0 0 16 16" class="bi bi-star-fill" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path d="M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.283.95l-3.523 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z"/>
</svg>
`;
emptyStar: string = `
<svg (click)="onClick()" width="2em" height="2em" viewBox="0 0 16 16" class="bi bi-star-fill" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path d="M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.283.95l-3.523 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z"/>
</svg>
`;
currentSymbol: string = this.emptyStar;
onClick() {
this.isClicked = !this.isClicked;
this.currentSymbol = this.isClicked ? this.fullStar : this.emptyStar;
}
}
Here's the star.component.html:
{{currentSymbol}}
-------
<svg (click)="onClick()" width="2em" height="2em" viewBox="0 0 16 16" class="bi bi-star-fill" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path d="M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.283.95l-3.523 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z"/>
</svg>
Here's the app.component.html, super basic:
<app-star></app-star>