I would like to display my enum as a string but it display as a number.
I am receiving a json object from a web service and mapping it to my typescript object
getProperties(): Observable<Property[]> {
return this.http.get<Property[]>(this.getallagentsproperties + '1');
}
export enum LetType {
Notspecified = 0,
LongTerm = 1,
ShortTerm = 2,
Commercial = 4
}
export class Property {
...other stuff...
letType: LetType;
...other stuff...
}
My component makes the call and adds it to the relevant property
import { Component, OnInit } from '@angular/core';
import { Property } from './Property';
import { PropertyService } from '../properties.service';
@Component({
selector: 'app-properties',
templateUrl: './properties.component.html',
})
export class PropertiesComponent implements OnInit {
properties: Property[];
constructor(private propertyService: PropertyService) { }
ngOnInit() {
this.getProperties()
}
getProperties(): void {
this.propertyService.getProperties()
.subscribe(p => this.properties = p);
}
}
When I display {{property.letType}}
in my template is displays:
4
I want it to display Commercial
I have tried to follow the answer found here in my template I added
{{LetType[property.letType]}}
and in my Componant I added
LetType = this.LetType;
but I always get the below error in the console
Cannot read property '4' of undefined
What am I doing wrong?