I am calling the function Allow() in html code, if returns true, will allow the user to Edit the data.
The functions $scope.GetCurrentStatus(), $scope.GetCurrentStatus() both are synchronous.
But it returns the following error in Allow() method.
Type Error: Cannot read property 'UserType' of undefined
Help me to handle the situation.
//LoadStatus
$scope.GetCurrentStatus = function () {
var defer = $q.defer();
$http({
method: "POST",
url: "../Documentation/Documentation.aspx/GetStatus",
data: {}
})
.then(function (response) {
defer.resolve(response.data.d);
$scope.Status = response.data.d;
}),
function (error) { data, status };
}
$scope.GetCurrentStatus();
//Load AccessRole
$scope.GetAccessRole = function () {
var defer = $q.defer();
$http({
method: "POST",
url: "../Documentation/Documentation.aspx/GetAccessRole",
data: {}
})
.then(function (response) {
defer.resolve(response.data.d);
$scope.Access = response.data.d;
}),
function (error) { data, status };
};
$scope.GetAccessRole();
$scope.Allow = function () {
if ($scope.Access.UserType == 'Admin' || !($scope.Status.Status == 'CC' || $scope.Status.Status == 'CD'))
return true;
return false;
}
GetCurrentStatusandGetAccessRoleare synchronous. You are using promises which made them async. By the time you are callingAllow(), you havent got your response.