Angularjs 具有自定义条件的NG-STYLE不点火
我在一个远程数据源中大大简化了以下项目Angularjs 具有自定义条件的NG-STYLE不点火,angularjs,function,conditional-statements,ng-style,Angularjs,Function,Conditional Statements,Ng Style,我在一个远程数据源中大大简化了以下项目 [ { "id": "3", "card_name": "Free Beer!", "count": "1" } <div ng-repeat="card in cardDetails"> <h1>{{card.card_name}}</h1> <button ng-style="set_hide(card)">Claim Me</button> </div&g
[
{
"id": "3",
"card_name": "Free Beer!",
"count": "1"
}
<div ng-repeat="card in cardDetails">
<h1>{{card.card_name}}</h1>
<button ng-style="set_hide(card)">Claim Me</button>
</div>
]
我有一个DIV和一个NG-REPEAT再次大大简化了
[
{
"id": "3",
"card_name": "Free Beer!",
"count": "1"
}
<div ng-repeat="card in cardDetails">
<h1>{{card.card_name}}</h1>
<button ng-style="set_hide(card)">Claim Me</button>
</div>
因此,基本上,如果这张卡的计数不是0 1+的话,按钮应该显示:无和消失
其余的信息,即卡片名称按预期呈现,如果我还添加了{{card.count},则按预期显示为1
但什么也没发生。没有错误,什么都没有
为什么我的ng风格没有开火
如果您只需要隐藏按钮,请提前感谢您的指导。一种更简单的方法是不使用函数set\u hide 您只需将ng hide属性插入到button元素 认领我你应该做:
$scope.set_hide = function (card) {
if (card.count > 0) {
return { display:'none' }
} else {
return { display:'block' }
}
}
您缺少“无”和“块”周围的引号。请编辑您的答案以包含一些解释。只有代码的答案对教育未来的读者几乎没有什么作用。您的答案因质量低而在审核队列中。ng-hide仍将该元素保留在DOM中,但不会显示它。可能更好的解决方案是ng-if.akshar:ng hide,ng if->差别可以忽略不计。你怎么知道“可能是更好的解决方案”???为什么呢?使用DOM进行更多不必要的操作??非常奇怪的建议。谢谢你的回答,但是ng hide解决了我的问题。谢谢你抽出时间来asnwer