I have an enum:
export enum NumberEnum {
One = 1,
Two = 2,
Three = 3
}
Within my component I have a successfully working call to a service which is passing back a result which has the associated properties returned with the enum values as integers:
export class DetailsComponent implements OnInit, OnDestroy {
details$: any;
number: NumberEnum;
ngOnInit(): void {
this.route.params.pipe(
switchMap(params => this.service.getDetails(params['details-id']))
).subscribe(result => {
this.details$ = result;
this.number = this.details$.Number as NumberEnum;
});
}
In my html when I try to display {{ number }} it is displaying the integer value as opposed to the string value which I would like. I have tried casting a different way...which looks like this:
this.number = NumberEnum[this.details$.Number];
but i get an error "Type 'string' is not assignable to type 'Number'" The code compiles and displays as I would like, I just know it's not best practise to have a red error line in my code.
Can't seem to find anything online which achieves what I want to do.