Angular JS ng-Switch基于ng-repeat内部值显示超链接

时间:2016-12-19 19:35:48

标签: angularjs html5

我正在尝试使用ng-switch来显示不同的超链接,例如修改/批准/拒绝但超链接没有显示在屏幕上,当我用它来显示它正在工作的文本时。我错过了什么这是我的HTML

<table>
<tr ng-repeat='item in errorsd'>
<td ng-switch={{val.action}} align="left" class="validationMsg">
<span ng-switch-when="View"><a href style="cursor: pointer" data-toggle="modal" data-target="#editWindow" ng-click="ModifyConfig(details)">Modify</a></span>
<span ng-switch-when=Approve><a href style="cursor: pointer" data-toggle="modal"data-target="#editWindow" ng-click="RejectConfig(details)">Reject</a></span>
  <!-- and so on.. -->
</td>

2 个答案:

答案 0 :(得分:1)

ng-switch-when需要表达式进行比较,因此用'(单引号)包装值就可以了。从{{}}指令中逐步删除ng-switch(插值指令),因为它只需要表达式。

<强>标记

<tr ng-repeat='item in errorsd'>
    <td ng-switch="val.action" align="left" class="validationMsg">
        <span ng-switch-when="'View'">
          <a href style="cursor: pointer" data-toggle="modal" data-target="#editWindow" ng-click="ModifyConfig(details)">Modify</a>
        </span>
        <span ng-switch-when="'Approve'">
          <a href style="cursor: pointer" data-toggle="modal"data-target="#editWindow" ng-click="RejectConfig(details)">Reject</a>
        </span>
    </td>
</tr>

答案 1 :(得分:0)

首先你的ng-repeat创建变量“item”, 应该在ng-switch中使用(“val”未知)

<td ng-switch="item.action">

然后你错过了这里的引用:

<span ng-switch-when=Approve>

工作示例here