krish
krish

Reputation: 1117

Pass string into a callback function

This is my code:

$scope.userDetails = function(userId, type) {
    ajax.get(orginalData.blockData.USER_BASIC_DETAILS + userId, $scope.getUserDetailsCallBack)
}

$scope.getUserDetailsCallBack = function(result) {
    console.log(result)
    $scope.empdetails = result.data.record;         
}

Here I need to pass type into callback method.If I pass like this, am getting Cannot read property 'record' of undefined error.

$scope.userDetails = function(userId, type) {
    ajax.get(orginalData.blockData.USER_BASIC_DETAILS + userId, $scope.getUserDetailsCallBack(type))
}

$scope.getUserDetailsCallBack = function(result, type) {
    console.log(result,type)
    $scope.empdetails = result.data.record;         
}

How to pass it?

Upvotes: 0

Views: 89

Answers (1)

Alexander Anikeev
Alexander Anikeev

Reputation: 701

$scope.userDetails = function(userId, type) {
    ajax.get(orginalData.blockData.USER_BASIC_DETAILS + userId, function (result) {
        $scope.getUserDetailsCallBack(result, type)
    });
}

Upvotes: 2

Related Questions