在angularjs中第一次调用时Javascript函数不工作

在angularjs中第一次调用时Javascript函数不工作,javascript,angularjs,Javascript,Angularjs,我基本上是在HTML按钮单击中调用$scope.ShowQuestionDetail函数。当我第一次点击时 $scope.questionJson值为空,因为getquestionData()函数不工作。当我第二次单击时,它工作正常 $scope.ShowQuestionDetail = function (questionID, displayEditLink, $index) { try { if ($scope.rdConceptExemplar

我基本上是在HTML按钮单击中调用$scope.ShowQuestionDetail函数。当我第一次点击时 $scope.questionJson值为空,因为getquestionData()函数不工作。当我第二次单击时,它工作正常

  $scope.ShowQuestionDetail = function (questionID, displayEditLink, $index) {
        try {
            if ($scope.rdConceptExemplarOn == true && $scope.conceptExemplarVisible == true) {
                $scope.IsCBC = true;
            } else {
                $scope.IsCBC = false;
            }
            var scrollToElement = '#avfq' + questionID;
            var questionTextElement = '#avfqQT' + questionID;
            $scope.displayEditLink = displayEditLink;
            $scope.questionID = questionID;
            getquestionData();
            var isQuestionExist = ($scope.QuestionAdded[$index] === undefined || !$scope.QuestionAdded[$index]) ? false : true;
            var promise = AssessmentBuilderServices.IsPilotInstitution($scope.institutionId);
            promise.then(function (results) {
                $scope.isCABPilotInstitution = results.data.IsPilotInstitutionResult.IsPilot;

                if ($scope.isCABPilotInstitution && $scope.questionJson) {

                    selectedTemplate = 'App/Components/Assessments/Questions/ViewFullQuestionIE.html';
                    selectedController = 'ViewFullQuestionIEController';
                    $scope.ViewFullQuestionIEModal(selectedTemplate, selectedController, questionID, isQuestionExist);

                }
                else {
                        // code for redirection to other controller
                }

            }, function (results) {
                    toaster.pop({ type: 'error', title: '', body: 'Error encountered while fetching pilot institution.', toastId: 'ShowQuestionDetail' });
            });

        }
        catch (err) {
            toaster.pop({ type: 'error', title: '', body: 'Error occurred while opening question details.', toastId: 'ShowQuestionDetail' });
        }
    }

                function getquestionData() {
            var searchText = '';
            var promise = AssessmentBuilderServices.GetQuestionDetail('Deprecated', $scope.questionID);
            promise.then(function (results) {

                if (results.data.GetQuestionDetailResult.IsError) {
                    toaster.pop({ type: 'error', title: '', body: results.data.GetQuestionDetailResult.ErrorMessage, toastId: 'getquestionData' });
                }
                else {
                    $scope.questionJson = results.data.GetQuestionDetailResult.QuestionJson;
                    $scope.questionTypeText = results.data.GetQuestionDetailResult.QuestionTypeText;

                }
            }, function (results) {
                toaster.pop({ type: 'error', title: '', body: 'Error occured while retrieving questionData information.', timeout: 4000, toastId: 'getquestionData' });
            });
        }