popconfirm doesn't work in table (<td>)

做~自己de王妃 提交于 2019-12-11 10:45:20

问题


I'm working in a scala application with playframework, I want to use the popover confirm in a smart-table, I did the install for the popconfirm ("popconfirm":"0.4.3") and it works well except in the table exactly in <td>

there is a part of my code:

<table st-table="topics" st-safe-src="topicList" class="table table-striped">
    <thead>
        <tr>
            <th st-sort="domain">Domain</th>
            <th class="text-center">Actions</th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="topic in topics">
            <td>{{topic.domain}}</td>
            <td class="text-center">
                <div class="btn-group btn-group-xs">
                    <a  href="javascript:void(0)" data-toggle="tooltip" data-original-title="Edit" class="btn btn-default" ng-click="showTopic(topic)" title><i class="fa fa-pencil"></i></a>

                    <button  href="" type="submit" data-toggle="tooltip" data-original-title="Remove" class="btn btn-danger popconfirm" ng-click="removeTopic(topic)" title><i class="hi hi-remove"></i>
                    </button>
                    <button type="submit" class="btn btn-success popconfirm" href="@routes.Application.index()">Test</button>  
                </div>           
            </td>
                    <button type="submit" class="btn btn-success popconfirm" href="@routes.Application.index()">Work</button>
        </tr>
    </tbody>
</table>
    <script src="@routes.Assets.versioned("temp/js/vendor/jquery-1.12.0.min.js")"></script>
    <script type="text/javascript">

        $(document).ready(function() {
            $(".popconfirm").popConfirm();  
        });
    </script>

the confirm button "work" is working well but test doesn't work, any help please?


回答1:


The above code is not working because, it is calling $(".popconfirm").popConfirm(); method before rendering ng-repeat(it render content lazily) content. So it is doing nothing.

For solving the issue, you need to create a directive that will enable popConfirm feature on that button once it get render by ng-repeat. You could use directive link function to get angular compiled element to call popConfirm() method of it.

Directive

app.directive('popconfirm', function(){
  return {
    restrict: 'C',
    link: function(scope, element){
      element.popConfirm();
    }
  }
})


来源:https://stackoverflow.com/questions/35915122/popconfirm-doesnt-work-in-table-td

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!