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