【发布时间】:2014-11-15 05:00:00
【问题描述】:
我正在尝试在 <tr ng-blur="blurFn()"> 上使用 ng-blur,但它不会触发。它仅在子 <input> 元素上触发。
这并不特定于 <tr> 或 <td>。根据 Angular documentation 的说法,ng-blur 对 blur event 做出反应,这不会“冒泡”。 "focusout" 事件冒泡,但没有 ng-focusout。
我是否遗漏了什么或者我需要创建一个新指令来处理焦点事件?
这里是代码 sn-p 和 fiddle:
html
<div ng-app="App">
<div ng-controller="Ctrl as ctrl">
<table>
<tr ng-repeat="item in ctrl.items" ng-blur="ctrl.blurFn()">
<td><input ng-model="item.A"/></td>
<td><input ng-model="item.B"/></td>
</tr>
</table>
</div>
</div>
js
angular.module("App", [])
.controller("Ctrl", function(){
this.blurFn = function($event){
console.log($event.target);
};
this.items = [
{A: "111", B: "222"},
{A: "111", B: "222"},
{A: "111", B: "222"},
{A: "111", B: "222"},
{A: "111", B: "222"}
];
});
【问题讨论】:
标签: javascript html angularjs dom angularjs-directive