gpt4 book ai didi

javascript - Angular,函数返回 true 但 ng-show 不起作用

转载 作者:行者123 更新时间:2023-11-28 18:20:26 25 4
gpt4 key购买 nike

如果我点击链接,showOrHide 函数将返回 true。

我使用alert和console.log函数测试了这段代码,它可以工作,但是如果我想在ng-show或ng-hide指令中测试这段代码,它就不起作用。我无法理解这个问题。

Sum:函数返回 false,如果我单击某个链接,它返回 true但 true 和 false 在 ng-show 中不起作用。

Angular.js 文件

$scope.showOrHide = function (value) {
if (typeof value !== 'undefined')
{
return alert(true);
//console.log("true");
//return true;
}else {
return alert(false);
//console.log("false");
//return false;
}
};
$scope.projectId = $stateParams.projectId;
$scope.showOrHide($stateParams.projectId);

html 文件

<tr ng-repeat="n in data.projects track by $index"
ng-href="@{{n.id}}"
ui-sref="goTo({ projectId: n.id })">
<td>@{{n.project_code}}</td>
<td>@{{n.project_name}}</td>
<td class="text-primary">will add</td>
<td class="text-primary">will add</td>
<td class="text-primary">@{{n.status}}</td>
<td ng-show="showOrHide">test</td>
</tr>

最佳答案

ng-show基于函数而不是变量,因此您需要将其编写为函数。

HTML:

<td ng-show="showOrHide('undefined')">test</td>

JS:

$scope.showOrHide = function (value) {
if (typeof value !== 'undefined')
return true;
else
return false;

};

关于javascript - Angular,函数返回 true 但 ng-show 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39986717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com