I need to upload the numeric value of an enum variable to a REST service.
How can I get the numeric value of the enum variable?
I tried the following two methods:
var enumVar: MyEnum = ...;
$http.put(url, { enumVar: enumVar });
This won't work also:
var enumVar: MyEnum = ...;
$http.put(url, { enumVar: <number>enumVar });
($http is AngularJS's HTTP service)
Both methods will lead to $http serializing the enum variable as a JSON object:
enumVar: {
Name: 'MyEnumMemberName',
Value: 2,
}
instead of just uploading the numeric value:
enumVar: 2,
The following works, but it is marked as an error, since the member .Value does not exist in TypeScript (it exists in Javascript):
var enumVar: MyEnum = ...;
var enumValue: number = enumVar.Value;
$http.put(url, enumValue);