Reputation: 8663
I have a $scope object that has a date property. I am trying to split that date into dd, mm and yyyy so i can perform calculations based on the values.
JS:
$scope.expenses = [
{
amount: 100,
SpentOn: '19/04/2014'
},
{
amount: 350,
SpentOn: '01/09/2013'
}
];
$scope.MySplitDateFunction = function () {
var data = [];
var data = $scope.expenses.SpentOn.split('/');
data.day = SpentOn[0];
data.month = SpentOn[1];
data.year = SpentOn[2];
return data;
};
I am getting the following error: $scope.expenses.SpentOn is undefined
Upvotes: 1
Views: 133
Reputation: 20751
since in your program $scope.expenses has two objects and you have not specifies which is that
Try this out
$scope.MySplitDateFunction = function () {
var data = [];
var data = $scope.expenses[0].SpentOn.split('/');
return data;
};
Upvotes: 1
Reputation: 17366
$scope.expenses
seems to be an array with objects, you have to try
$scope.expenses[0].SpentOn
Upvotes: 1
Reputation: 10994
$scope.expenses
returns an array with 2 objects in it so you'll have to do something like
$scope.expenses[0].SpentOn // returns 19/04/2014
Or you can remove the []
to make it an object and not an array of objects
Upvotes: 1