【问题标题】:Angular ng-show won't eval correctlyAngular ng-show 无法正确评估
【发布时间】:2016-02-21 22:25:52
【问题描述】:

所以如果我的 JSON 数组对象返回这个:

"Tools": [
{
  "name": "Submit a Claim",
  "position": 1,
  "isOn": true,
  "alert": null
},
{
  "name": "My Recurring Claims",
  "position": 2,
  "isOn": true,
  "alert": null
},
{
  "name": "Online Enrollment",
  "position": 3,
  "isOn": false,
  "alert": "Online enrollment is available for the upcoming plan year. Click here to enroll!"
},

我的 ng-show html 有这个:

<div class="toolTile col-md-3" ng-show="Tools.name = 'Online Enrollment' && Tools.isOn==true ">
    <a href="#/claimEnter">
        <img class="toolIcon" src="ppt/assets/toolIcons/oe.svg">
        <p>Online Enrollment</p>
    </a>
</div>
<div class="toolTile col-md-3" ng-show="Tools.name = 'Submit a Claim' && Tools.isOn==true ">
    <a ng-click="transId()" ng-href="{{ ppt.Globals.hasDebitCard ? '#/claimEnter' : '#/claimSub' }}" >
        <img src="ppt/assets/toolIcons/submitclaim.svg" >
        <p>Submit a Claim</p>
    </a>
</div>

为什么它一直评估为假?我尝试了很多变体,“在线注册”应该隐藏,而“提交索赔”应该显示。

关于我在这里可能做错了什么的任何想法?

非常感谢。

【问题讨论】:

  • 忘记了==?在Tools.name = 'Submit a Claim'

标签: html arrays angularjs json


【解决方案1】:

嗨,伙计,你不能在没有头尾的情况下发布代码。有一些 导致问题的语法错误。

您至少需要为 Plunker 提供带有 Buggy 代码的一些帮助 :-)。

当您在对象中获得一个数组时,您需要对其进行迭代。

我为你提供了一个正在运行的 Plunker:-

    <div ng-repeat="tool in data.Tools">
               <div ng-show="tool.name == 'Online Enrollment' && tool.isOn==false ">
                    Online Enrollment
                </div>

                <div ng-show="tool.name == 'Submit a Claim' && tool.isOn == true ">
                   Submit a Claim
                </div>

                </div>  

Plunker:-

http://plnkr.co/edit/B01pKWLsUtA2JlTAPOd5?p=preview

祝你好运!如果有任何疑问,请告诉我!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-27
    • 2019-05-10
    • 2013-06-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多