AngularJS函数执行顺序问题

AngularJS function execution sequence question

我在点击按钮时在 Angular 控制器中使用调用函数 Save_Click。

执行顺序如下

Line Code 
1    Declare a variable V1 
2    console.log(V1) 
3    Perform a server post back, and assign a value to V1 depending on the values the service returns. console.log(V1)
4 console.log(V1) 

我看到的是 - 在控制台 #4 之前打印 - #3 此外,#3 中分配的值未打印在#4 中。

可能是什么原因?我做错了什么? 如果我也使用 $localStorage (ngStorage) 库,我也会遇到同样的问题。

注意 - 我正在使用 Visual Studio/.Net 解决方案在我的 Index.cshtml 中托管 angular 应用程序。

使用以下方法

1    Declare a variable V1 
2    console.log(V1) 
3    async (Perform a server post back, and assign a value to V1 depending on the values the service returns. await console.log(V1))
4    console.log(V1) 

现在 #3 将在 #4 之前打印

我终于成功了。



var x = {};
            
                    x.1 = '1';
                    x.2 = '2';
                   
                    MyService.CallAPI('RunRabbit', x).success(function (data) {
                        if (data === null) {
                            $scope.error = true;
                            $scope.errorDescription = "No data found for selected criteria.";
                            
                        } else {
                           
                            $scope.answer = data.answer;
                           
                        }
                    }).error(function () {

                    }).finally(function () {
                        console.log($scope.answer);
                    });

我可以评估 $scope.answer 然后从最后以同步方式使用它。