简体   繁体   English

响应模式下的数据表ng-click不起作用

[英]Datatable in responsive mode ng-click doesn't work

I have a datatable that is populated by angulars ng-repeat. 我有一个由angulars ng-repeat填充的数据表。 the code below is what I am using, I have only changed the headers and what is being repeated. 下面的代码是我正在使用的代码,我只更改了标题并重复了什么。

It all works perfectly until I test it on a mobile device and the table turns responsive, adding the little circled + sign to expand and view the data from the hidden columns. 一切正常,直到我在移动设备上对其进行测试并且表格开始响应,并添加带圆圈的小号+来展开并查看隐藏列中的数据。 When this happens the "More Info" button simply doesn't work any more. 当发生这种情况时,“更多信息”按钮将不再起作用。

From what I have surmised, the information that appears when you click the little + sign is dynamically added at the time you click it, meaning the "more info" button is a duplicate of the original which is still in the hidden table column. 根据我的推测,单击小号+时出现的信息会在您单击时动态添加,这意味着“更多信息”按钮与原始内容重复,该内容仍位于隐藏表列中。 I believe that is causing the ng-click event to not be "wired up". 我认为这会导致ng-click事件无法“连接”。

Does anyone know if I'm correct and/or how to fix this? 有谁知道我是否正确和/或如何解决此问题?

<table id="dtTransactions" datatable="ng" class="table table-bordered dt-responsive dataTable no-footer dtr-inline collapsed">
    <thead>
        <tr>
            <th>header 1</th>
            <th>header 2</th>
            <th>header 3</th>
            <th>header 4</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="person in people">
            <td>{{ person.name }}</td>
            <td>{{ person.age }}</td>
            <td>{{ person.eyecolour }} }}</td>
            <td>{{ person.shoesize }} }}</td>
            <td align="center">
                <button type="button" class="btn btn-default" ng-click="doSomething(person)">More Info</button>
            </td>
        </tr>
    </tbody>
</table>

Here is my typescript for the controller. 这是我的控制器打字稿。 I'm very new to using typescript and am essentially copying what is already in this system and rejigging it for my own work: 我对使用打字稿很陌生,本质上是在复制此系统中已有的内容,然后重新调整它以进行自己的工作:

module app.agreement {
    'use strict';

    class DetailController {
        // some variable declared

        static $inject = ['$compile', '$scope', 'data', 'app.services.AgreementService', '$mdDialog']
        constructor(private $compile: ng.ICompileService, 
                    private $scope: ng.IScope, 
                    private data: any, 
                    private agreementService: app.services.IAgreementService, 
                    private mdDialog: angular.material.IDialogService) {

            $('#dtTransactions').on('responsive-display', function () {
                alert('asd');
                //var c = $compile($('#dtTransactions').html());
                //c($scope);
                //$scope.$apply();
            });

            this.init();
        }

        init(): void {
            // variables initialised
        }
    }

    angular.module('app.agreement')
        .controller('app.agreement.DetailController', DetailController);
} 

我认为您需要用于移动设备的ngTouch

Your approach to achieve your functionality is wrong. 您实现功能的方法是错误的。 You may try workaround with $index without repeating button as below. 您可以尝试使用$ index解决方法而无需重复按钮,如下所示。

<tr ng-repeat="person in people">
        <td>{{ person.name }}</td>
        <td>{{ person.age }}</td>
        <td>{{ person.eyecolour }} }}</td>
        <td>{{ person.shoesize }} }}</td>
        <td align="center">
            <button type="button" class="btn btn-default" ng-click="doSomething($index)">More Info</button>
        </td>
    </tr>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM