回调比应提前发射(均值堆栈)



我有两个函数getcharacterinfo(callback)和apply()。我将apply()称为getCharacterinfo中的回调,但申请(回调)比应该(至少从我可以从代码中告诉的内容)触发。

这是我的代码:

getcharacterinfo(回调)

$scope.getCharacterInfo = function(callback) {
    temp = $http.get('https://eu.api.battle.net/wow/character/' + $rootScope.current_user_realm + '/' + $rootScope.current_user + '?locale=en_GB&apikey=hidden');
    temp.then(function onSuccess(response){
        $scope.charInfo = response.data;
        $scope.charInfo.thumbnail = "https://render-api-eu.worldofwarcraft.com/static-render/eu/" + response.data.thumbnail
        console.log("$scope.charinfo = " + $scope.charInfo)
        console.log("response.data = " + response.data)
        if(callback) {
            callback();
        }
    })
}

应用()

$scope.apply = function() {
            $scope.newApplication.charName = $scope.charInfo.name;
            $scope.newApplication.realm = $scope.charInfo.realm;
            $scope.newApplication.armoryLink = 'http://eu.battle.net/wow/en/character/'+ $scope.charInfo.realm + '/'+ $scope.charInfo.name +'/advanced'
            console.log($scope.newApplication)
            applicationsService.save($scope.newApplication, function(){
                $scope.applications = applicationsService.query();
                $scope.newApplication = null;
            });
    };

函数调用是由HTML-Submit表单

进行的
<form ng-Submit="getCharacterInfo(apply())">

我遇到的错误是在应用程序中(),控制台告诉我$ scope.Charinfo未定义。还有console.log()在字符中的s永远不会被解雇,我认为他们应该吗?

我错了什么?

通过apply参数没有括号:

<form ng-submit="getCharacterInfo(apply)">

否则,函数apply首先执行,然后将其结果传递给getCharacterInfo函数。

最新更新