在Angular中使用ng-click嵌套div

时间:2015-10-15 19:44:12

标签: javascript angularjs

有以下代码:

<div class="first" ng-click="funcFirst()">
  ... Some other content
  <div class="second" ng-click="funcSecond()">
  </div>
  ... Some other content
</div>

我想做以下事情:如果我点击“第一”div中除“second”之外的任何内容 - 执行funcFirst函数;如果我点击“秒”div - 执行funcSecond函数。现在,如果我点击“秒”,我执行funcFirst。我该怎么做?我无法改变HTML结构。提前致谢。

1 个答案:

答案 0 :(得分:5)

我有解决方案:

脚本示例:

 <script>
    myWebApp = angular.module('myWebApp', []);
    myWebApp.controller("Controller01", function ($scope) {

        $scope.funcFirst = function () {
            alert("click on div 1 content");
        };

        $scope.funcSecond = function () {
            alert("click on div 2 content");
        };
    });

</script>

HTML

<body ng-app="myWebApp">
<div ng-controller="Controller01">

    <div class="first" ng-click="funcFirst()">
        ... click on div 1 content
        <div class="second" ng-click="funcSecond(); $event.stopPropagation();">
            click on div 2 content
        </div>
        ... click on div 1 content
    </div>
</div>

关于plunker的

Edit

相关问题