javascript - 在 angularjs 中第一次调用 Javascript 函数时不起作用
问题描述
我基本上是在 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' });
});
}
解决方案
推荐阅读
- blockchain - 如何使用 decl_storage 中的 struct 映射 rust 原语!基板中的宏
- angular - 部署iis后未加载Angular svg图像
- java - 尝试以墨西哥波浪样式模式将字符更改为大写
- node.js - 不断从流响应中获取 Node js 中损坏或受密码保护的 PDF
- unit-testing - NET CORE - 单元测试 - CustomWebApplicationFactory
- reactjs - 如何映射对象的槽数组并切换选定的布尔属性
- sql-server - 计算 SQL 连接上的缺失值
- java - 如何有效地从rest api下载文件并将其发送到像RabbitMq这样的消息代理?
- c++ - C++ 错误:在抛出 'std::bad_alloc' what() 的实例后调用终止:std::bad_alloc
- powerbi - 如何在power bi中制作一个包含3个表格的折线图