【问题标题】:how to get select event of element in angular?如何以角度获取元素的选择事件?
【发布时间】:2016-01-19 00:32:01
【问题描述】:

您能告诉我如何在 angular 中获取元素的选择事件吗? 我用这个 github 做了一个演示 https://github.com/codecapers/AngularJS-FlowChart

现场演示 https://dl.dropboxusercontent.com/u/16408368/WebUI_FlowChart/index.html

在演示中,用户可以选择节点并删除节点。我想获得节点的点击事件。我想获得选定的对象。 我们可以在角度js中获取选定的对象或节点的点击事件吗

这是我的代码 http://plnkr.co/edit/vTgDa3AfY8aiWVgUgZf8?p=preview

<div ng-controller="cntrl" style="width: 100%; height:100%;">
     <div style="width: 100%; height:100%;">
     <flow-chart
        style="margin: 5px; width: 100%; height: 100%;"
        chart="chartViewModel"
        >
    </flow-chart>
    </div>
   </div>

有什么更新吗?

【问题讨论】:

  • 您不能将 ng-click="someFunc" 附加到每个节点并在您的视图模型中捕获该事件吗?

标签: javascript angularjs angularjs-directive angularjs-scope angular-ui-router


【解决方案1】:

该流程图指令是第三方还是您构建的?

如果不是第 3 方,可以编辑指令并添加点击事件:

angular.module('myApp').directive('myDocumentClick', 
    ['$window', '$document', '$log',
    function($window, $document, $log) {
      return {
        restrict: 'A',
        link: function(scope, element, attrs) {
          $document.bind('click', function(event) {
            $log.info(event);
            if (angular.element(event.target).hasClass('myClass')) {
              $window.alert('Foo!');
            }
          })
        }
      };
    }
  ]);

【讨论】:

  • 这也是一个选项:您可以将 ng-click="myFunction($event)" 添加到元素中
  • 我的回答对您有帮助吗?如果是这样,您能否投票给我的答案或将其设置为选定的答案?
猜你喜欢
  • 1970-01-01
  • 2023-01-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-25
  • 2023-02-10
  • 2015-10-09
相关资源
最近更新 更多