AngularJS:带链接的表

时间:2013-11-07 22:30:48

标签: javascript angularjs

我想在AngularJS中创建一个表,它应该是这样的:

id  |  weekday  |  time  | Actions
1   |  Mon      | 10:10  | Edit-Link, Delete-Link
2   |  Tue      | 15:19  | Edit-Link, Delete-Link

我的代码是:

<html ng-app>
    ...
    <script type="text/javascript">
        function DB($scope) {
            $scope.currentQs = null;
            $scope.jsons = JSON.parse('${jsons}');
            $scope.edit = function(id) {
                console.log("Edit " + id);
            }
            $scope.delete = function(id) {
                console.log("Delete " + id);
            }
        }
    </script>
    <body ng-controller="DB">
        <table>
            <tbody ng-repeat="qs in jsons">
                <tr>
                    <td>{{qs.query_id}}</td>
                    <td>{{qs.weekday}}</td>
                    <td>{{qs.hour}}:{{qs.minute}}</td>
                    <td>
                        <!-- I guess, I'm thinking in the wrong way with the a-tags -->
                        <!-- How do I put the current object (qs) as $scope.currentQs -->
                        <a href="#" ng-click="edit('{{qs.query_id}}')">Edit</a>
                        <a href="#" ng-click="delete('{{qs.query_id}}')">Delete</a>
                    </td>
                </tr>
            </tbody>
        </table>
    </body>
</html>

好的,桌子很好。但是什么是设置的正确方法 编辑和删除链接?

感谢。 哈德

PS:昨天刚开始看AngularJS。

1 个答案:

答案 0 :(得分:6)

ng-click内,您不需要插入{{ }},因为它已经在角度执行上下文中:

<a href="#" ng-click="edit(qs.query_id)">Edit</a>
<a href="#" ng-click="delete(qs.query_id)">Delete</a>

所以,上面的内容适合你。