I have an Enum:
export enum DistanceMeasure {
Miles, Kilometers
}
To use in a user object:
export class User {
... some stuff
MaxTravelDistance: number;
DistanceMeasure: DistanceMeasure;
MaxTravelTime: TimeSpan;
... some more stuff
}
So the info comes from the server as 0 (zero) or 1 for the DistanceMeasure and thats fine. But I need to present the string e.g. "Miles".
In my (Angular/Ionic) app, the output of
console.log(user.DistanceMeasure);
is '0' (zero). However I read that to extract the enum string you should use it as an index. If I do:
console.log(user.DistanceMeasure[0]);
It comes back as undefined.
Why is that? since the user.DistanceMeasure is of type DistanceMeasure? Is it no longer an enum ? Thanks.
DistanceMeasure[0]should outputMiles.user.DistanceMeasureis not an array nor an object . it's a property of theUserclass and it's value can be something defined in theDistanceMeasureenum