【发布时间】:2016-03-08 07:14:47
【问题描述】:
我收到来自 web 服务的响应为“未找到附件”和“找到附件”。我想在一个页面上显示 2 个不同的图像,一个在没有找到附件的情况下,另一个在发现附件的情况下。
这是我的html:
<div style="float:left">
<img src="img/icon_doc_active.png " style="width:20px" ng-if="hasdocument(response == "attachment found")" ng-click="findDoc() "></img>
<img src="img/icon_doc_inactive.png " style="width:20px" ng-if="!hasdocument(response=="no attachment found")"></img>
</div>
这是我的控制器:
$scope.responseofdoc = [];
$scope.findDoc = function() {
$scope.urlObj = [];
$scope.docCheck = false;
$scope.docListCheck = false;
$scope.cLoader = true;
$scope.docMsg = "No Attachment found";
$scope.docModalOpen = true;
attachmentService.fetchAttachmentId(temp).then(function(response) {
console.log(response);
if (response == "No Attachments found") {
console.log("my response");
$scope.responseofdoc.push(response == "No Attachments found");
console.log( $scope.responseofdoc);
$scope.docMsg = response;
$scope.docCheck = true;
$scope.cLoader = false;
// $scope.docListCheck = false;
} else {
console.log("found attachment");
console.log("my response");
$scope.docListCheck = true;
var data = JSON.parse(response);
// $scope.urlObj = [];
getDocBase64(data);
}
},
function(error) {
console.log(error);
$scope.docMsg = "Error while fetching attachment";
$scope.docCheck = true;
$scope.cLoader = false;
});
}
我将如何检查 $scope.responseofdoc = []; 中的字符串响应在我的 html 中带有 ng-if 条件的数组并显示所需的文档图像?
【问题讨论】:
-
试试这个 -> ng-if="hasdocument(response == 'attachment found')"
-
我是否应该创建另一个函数来检查响应的值 bcz 我使用它到 findDoc 函数中。并将他的值推入 $scope.responseofdoc 数组?
标签: javascript angularjs ionic-framework factory