0

我正在尝试将$focused属性添加到我的输入字段(如$touched$valid)。这是我当前的代码:

directive('ngModel', function () {
  return {
    restrict: 'A',
    require: 'ngModel',
    link: function ($scope, $element, $attrs, ngModelScope) {
      $element.on('focus', function () {
        ngModelScope.$focused = true
      })
      $element.on('blur', function () {
        ngModelScope.$focused = false
      })
      ngModelScope.$focused = false
    }
  }
})

..它不工作。似乎$digest没有触发,并且使用 ngModelScope 所做的更改不适用于 dom。

HTML:

<form novalidate name="loginForm">
  <input type="email" placeholder="Email" name="email" ng-model="email" >
  <span ng-show="loginForm.email.$focused">Focused</span>
</form>
4

0 回答 0