将字符串传递给回调函数

时间:2017-08-08 06:27:16

标签: angularjs

这是我的代码:

$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;         
}

我需要将type传递给callback方法。如果我这样通过,则会出现Cannot read property 'record' of undefined错误。

$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;         
}

如何通过?

1 个答案:

答案 0 :(得分:2)

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