【问题标题】:HTML link inside Table Angular jsTable Angular js中的HTML链接
【发布时间】:2015-08-04 17:16:30
【问题描述】:

我正在使用 Angular js; 在我的视图模板中,我有一个表 我希望由模型中的元素填充的表格的每一行都成为另一个页面的链接。 我尝试了注释的代码行,但它不起作用!

感谢您的帮助! 干杯!

<section data-ng-controller="AllsController" data-ng-init="find()">
<div class="page-header">
    <h1>Alls</h1>
</div>

<div class="list-group">

    <table class="table table-striped table-bordered">
        <thead>
            <tr>
                <th>Created</th>
                <th>User</th>
                <th>Name</th>
                <th>Color</th>
            </tr>
        </thead>
        <tbody>
                <tr data-ng-repeat="all in alls">
                <!-- <a data-ng-href="#!/alls/{{all._id}}" > -->

                <td data-ng-bind="all.created | date:'medium'"></td>
                <td data-ng-bind="all.user.displayName"></td>
                <td data-ng-bind="all.name"></td>
                <td data-ng-bind="all.color"></td>

                <!-- </a> -->
            </tr>
        </tbody>
    </table>
</div>

【问题讨论】:

  • 你不能像这样包装&lt;td&gt; 元素。您可以尝试将ngClickngHref 处理程序添加到&lt;tr&gt;,但这也可能不起作用。如果没有,只需将 click/href 处理程序添加到每个 &lt;td&gt; 元素。我的猜测是ngHref 也不起作用,因此您可能必须在控制器中处理点击。

标签: html angularjs


【解决方案1】:

你可以做类似的事情 &lt;tr ng-click="onClick()"&gt; 在你的 onClick 函数中你可以编写你的逻辑。如果你想重定向到某个页面,你可以使用 angularjs 的 $location 服务。

【讨论】:

  • 如果我使用 angular,我不会在 onclick 上使用 document.location
猜你喜欢
  • 2016-06-21
  • 2013-08-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-31
  • 1970-01-01
  • 2017-05-31
相关资源
最近更新 更多