Anular JS issue

rashmitha r 21 Reputation points

I want get the leavebalance to my view using angular. Here is my code
$scope.LeaveApplyBalanceDataSource = {};
$scope.checkBalance = function () {
method: "GET",
url: "/ESS/GetAllLeaveBalanceByLeaveType",
params: { LeaveTypeId: $scope.LeaveApply.LeaveTypeId },
cache: false
.success(function (data) {
$scope.LeaveApplyBalanceDataSource = data;
$scope.TotalBalance = data.Balance;
$scope.TotalApply =data.TakenLeaves;
$scope.TodalDays =data.Days;


And it shows the result like below in data
Now i want that balance, takenleaves and days in scope value. but it is giving result as 'un-defined'.

A set of technologies in the .NET Framework for building web applications and XML web services.
4,025 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 45,246 Reputation points

    This is really just a JS issue. Look at the type of data. It is an array, not an object. The call you're making is returning back an array so if you expect only 1 value back then you'll need to get the first item in the array.

       //Ignoring error checking here...  
       var item = data[0];  
       $scope.TotalBalance = item.Balance;  

0 additional answers

Sort by: Most helpful