事件传播不适用于AngularJs?

时间:2017-03-10 17:47:11

标签: javascript jquery angularjs angularjs-directive

我制作了一个自定义contextmenu指令。我正在尝试在contextmenu打开时记录某些内容。但是当它应该运行一次时,相同的功能运行5次。我想e.stopPropagation();但CSS从第一次开始就不适用,我必须再次点击,然后才能正常工作。我究竟做错了什么?

以下是指令中我的链接功能的显示方式:

$ele.on('contextmenu', '*', function(e) {
    e.preventDefault();
    e.stopPropagation();

    $scope.$apply(function () {

        $scope.visible = true;
        $('.parented').css({left:e.pageX, top:e.pageY, position: 'absolute'}).show();
        var ele = e.target;

        $scope.souls = {
            elementType: ele.nodeName,
            content: ele.innerText,
            id: ele.id,
            class: ele.className
        }

        console.log($scope.souls)
    })
});

HTML

<div prevent visible="isVisible" ravi="someData" sound="sound(souls)" souls="souls">

    <p class="haseebtesting">abc</p>
    <table class="datatable">
        <tr ng-repeat="t in templateData">
            <td class="haseebtesting" ng-click="current.selected = t; confusedFunction(t)" id="{{'test ' + $index}}">{{t.templateName}}</td>
            <td>{{t.templatePath}}</td>
        </tr>
    </table>
    {{souls}} <br /><br />

    <div ng-if="isVisible" class="parented">
        <div class="btn-group-vertical notclick" role="group" aria-label="Vertical button group">
            <form class="haseebform">
                <input type="text" ng-model="souls.entername" placeholder="Enter name"> <br>
                <input type="text" ng-model="souls.entercomment" placeholder="Enter comment">
                <input type="button" class="btn btn-info" ng-click="addT(souls)" value="Submit">
            </form>
        </div>
    </div>

</div>

此处的工作链接:https://aijazkhan81.github.io/contextmenu/

0 个答案:

没有答案