如何比较匹配角度表达式与特定单词

时间:2017-05-18 13:29:30

标签: angularjs if-statement expression

我有3种文档类型。

  • 文件
  • 文件夹
  • documentplace

如果表达式是{{documenttype}} = document,则创建文档图标。 如果表达式是{{documenttype}} =文件夹而不是创建文件夹图标。 如果表达式是{{documenttype}} = documentplace而不是创建地址图标。

我非常清楚地知道在PHP中这样做了,但是有点过分了。

1 个答案:

答案 0 :(得分:0)

您可以使用ng-switch来完成这项工作。它将评估on中的表达式,并根据值显示div

<div ng-switch on="documenttype">

    <div ng-switch-when="document">
        <img src="document.png"/>
    </div>

    <div ng-switch-when="folder">
        <img src="folder.png"/>
    </div>

    <div ng-switch-when="documentplace">
        <img src="documentplace.png"/>
    </div>

</div>