AsyncValidators bug using directives
A sort of issue I found in AngularJS. I'm not sure if it's a bug.
HTML
<div ng-app="myApp" ng-controller="myController">
<form name="myForm">
This value is safe and will propagate changes every time: <br>
{{data.safeValue}}<br>
<input type="text" ng-model="data.safeValue" name="safeValue"><br>
This value is unsafe because of the update to asyncValidators and will break<br>
{{data.unsafeValue}} <br>
<input type="text" ng-model="data.unsafeValue" add-async name="unsafeValue"><br>
</form>
</div>
JavaScript
console.log(angular.version.full)
angular.module('myApp', [])
.directive('addAsync', function($q){
return {
require: 'ngModel',
link: function(scope, element, attr, ctrl) {
ctrl.$asyncValidators.breaking = function(modelValue, viewValue) {
console.log(arguments)
if (ctrl.$isEmpty(modelValue)) {
return $q.when();
}
return $q.defer().promise
};
}
}
})
.controller('myController', function($q, $scope){
var self = this;
$scope.data = {
safeValue: "foo",
unsafeValue: "bar"
};
});