【问题标题】:validation message hide in angular js验证消息隐藏在角度js中
【发布时间】:2020-08-02 15:32:32
【问题描述】:

我使用下面的代码作为验证消息。如果它的成功消息,我试图隐藏我的验证消息。请检查我的代码

    <div uib-alert ng-repeat="alert in alerts"  ng-class="'alert-' + (alert.type || 'info')" dismiss-on-timeout="{{alert.type == success ? '5000' : ''}}"
    close="alerts.splice(index, 1)">
   {{alert.msg}}

警报。类型可以是“成功或错误”。只有在“alert.type=success”时,我才需要隐藏它。我试过了。但不工作。我如何添加条件。谢谢

【问题讨论】:

  • 这不是我的问题。 “dismiss-on-timeout”应该只对成功消息起作用,(alert.type==success)
  • 成功是alert.type == success ? '5000' : ''中的变量吗?
  • alert.type 变量可以是“成功”或“错误”
  • 我需要隐藏我的 div ,只有 alert.type = success

标签: javascript angularjs


【解决方案1】:

您需要使用字符串success5000 作为数字,否则条件将是none 而不是''。结合所有这些,您将需要:

dismiss-on-timeout="{{ alert.type == 'success' ? 5000 : 'none' }}"

Plunkr example

【讨论】:

  • :) 乐于助人
猜你喜欢
  • 2012-10-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-19
  • 1970-01-01
  • 2012-12-03
  • 2017-12-26
  • 1970-01-01
相关资源
最近更新 更多