I am trying to add $focused
property to my input fields (like $touched
or $valid
). Here is my current code:
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
}
}
})
..and it's not working. Seems like the $digest
is not firing and changes made with ngModelScope are not applying to 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>