我正在尝试将$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>