哪个元素着重于处理ng-blur

时间:2018-08-29 11:14:20

标签: angularjs typescript

我试图弄清楚如何获得有效成分|处理obj1.getMappingResult().putAll(obj2.getMappingResult()); String jsonString = objMapper.writeValueAsString(obj1); 事件时将焦点对准元素。我尝试过ng-blur,但它始终是“ body”。

HTML

window.document.activeElement

打字稿

<body>
  <div name="element1" ng-blur="$ctrl.onBlur($event)">element1</div>
  <div name="element2" ng-blur="$ctrl.onBlur($event)">element2</div>
</body>

编辑

使用public onBlur($event: any): void { var value = $event.target.attributes["name"].value; // value is the name of the element where the event is triggered // but how to get the element to where the focus has gone to? } 服务将其修复。

$timeout

1 个答案:

答案 0 :(得分:0)

使用$ timeout服务修复了该问题。

public onBlur($event: any): void {
   this.$timeout(() => {
      if (this.$window.document.activeElement) {
         // do things
      }
   }, 1);
}