This is a function that I call on ng-click.
HTML
<div class="col-md-offset-10">
<div class="form-group">
<a class="btn btn-default" ng-click="schedule ()">Add</a>
</div>
</div>
JS
$scope.scheduleid={};
var inc=0;
$scope.schedule = function ()
{
inc += 1;
console.log($scope.from);
console.log ($scope.dateObj);
if (inc == 1)
{
var schedule = {}
schedule._type = "Schedule";
console.log($scope.dateObj);
var insertSchedule = BasicJSONCreator.basicEdit ();
insertSchedule.Calls[0].Arguments = [];
insertSchedule.Calls[0].Arguments[0] = schedule;
httpRequester.async (insertSchedule).then (function (data) {
console.log(data.data.ReturnValues[0].scheduleID);
$scope.scheduleid=data.data.ReturnValues[0] //This gets a response from my database
console.log($scope.scheduleid ); // retrieves data from the database
});
}
$scope.getData();
}
This function is meant to retrieve results from $scope.scheduleid
, but there seems to be an issue here.
When I click once, $scope.scheduleid
is empty. However, with two or more clicks, $scope.scheduleid
is not empty and contains data. Why is it empty on the first click?
$scope.getData=function()
{
console.log($scope.scheduleid)
// The object is empty after one click, but contains data after two or more clicks
}