<div ng-repeat='employee in filteredStaff ' ng-click="describeEmployee(employee)" >
<div class="gridNameTd">
<div ng-click="addTeamMember(employee)">{{getEmployeeByName(employee.name).name}} </div>
</div>
</div>
这是我的代码的一部分。点击这两个&#39;叫做。我只需要内部ng-click =&#34; addTeamMember(员工)。 如何处理?
答案 0 :(得分:6)
您需要让事件不通过DOM树冒泡。在您的点击上,即使您可以传递该事件并告诉它不要通过$event.stopPropagation
这是一个工作的掠夺者:http://plnkr.co/edit/OjiFIjCEQ7jDG2owm33D?p=preview
示例:
在您的控制器中:
$scope.addTeamMember = function($event, employee) {
$event.stopPropagation();
// do stuff....
}
在您的HTML中:
<div ng-repeat='employee in filteredStaff ' ng-click="describeEmployee(employee)" >
<div class="gridNameTd">
<div ng-click="addTeamMember($event, employee)">{{getEmployeeByName(employee.name).name}} </div>
</div>
</div>
答案 1 :(得分:0)
<div ng-repeat='employee in filteredStaff'>
<div class="gridNameTd">
<div ng-click="addTeamMember(employee)">{{getEmployeeByName(employee.name).name}} </div>
</div>
</div>
答案 2 :(得分:0)
尝试使用$event.stopPropagation()
停止内部事件的传播,如下所示:
<div ng-repeat='employee in filteredStaff ' ng-click="describeEmployee(employee)" >
<div class="gridNameTd">
<div ng-click="addTeamMember(employee); $event.stopPropagation()">{{getEmployeeByName(employee.name).name}} </div>
</div>
</div>