I have this View Model returned from MVC REST service:
[DataContract]
public class AccountViewModel
{
[DataMember]
public IEnumerable<string> Currencies { get; set; }
[DataMember]
public IEnumerable<string> FromAccounts { get; set; }
[DataMember]
public IEnumerable<string> ToAccounts { get; set; }
}
I have this in angular:
angular.module('accountServices', ['ngResource'])
.factory('Accounts', function($resource) {
return $resource('/SomeUrl/Accounts', {}, {
get: { method: 'GET' }
});
});
angular.module('staticDataServices', ['accountServices'])
.service('StaticData', function (Accounts) {
self.AccountViewModel = Accounts.get();
self.Reasons = ['Incorrect Alloc',
'Unallocated',
'Client Withdrawal',
'Margin Topup',
'Margin Reduction',
'Other'];
return self;
});
webtraderDeposits.controller('ApprovalDialogController', ['$scope', 'dialog', 'item', 'StaticData', 'Deposits',
function ($scope, dialog, item, StaticData, Deposits) {
$scope.AccountViewModel = StaticData.AccountViewModel;
$scope.Reasons = StaticData.Reasons;
alert(StaticData.AccountViewModel.Currencies);
} ]);
StaticData.AccountViewModel
is an Object, but StaticData.AccountViewModel.Currencies
is undefined. Any ideas on what i am doing wrong?
The webservice returns the following data:
<AccountViewModel xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/WebtraderBackOffice.RESTService.Models">
<Currencies xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d2p1:string>USD</d2p1:string>
</Currencies>
<FromAccounts xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d2p1:string>59500/FUSD</d2p1:string>
</FromAccounts>
<ToAccounts xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d2p1:string>59504/6227905</d2p1:string>
<d2p1:string>59504/6227925</d2p1:string>
<d2p1:string>59504/6227951</d2p1:string>
<d2p1:string>59504/6227958</d2p1:string>
<d2p1:string>59504/6227959</d2p1:string>
<d2p1:string>59505/50203040</d2p1:string>
<d2p1:string>59505/6567866</d2p1:string>
</ToAccounts>