Reputation: 1777
In my custom directive, I need to update the validity of another input. The directive is something like this :
<customDirective="foo">
, in which the value foo is the name of another ngModel.
In my direcitve, I can get its model by :
var foo = scope[attrs.foo];
.
But how can I get its ngModelController, to set its validity? Just like this :
fooModelController.$setValidity('customDirective', true);
EDIT :
In html, the input is defined as :
<input type="text" name="dateDebut" id="dateDebut" class="form-control" ng-model="formData.dateDebut" customDirective="dateFin" required>
<input type="text" name="dateFin" id="dateFin" class="form-control" ng-model="formData.dateFin" customDirective="dateDebut" required>
I get the dom node by angular.element.find(document.querySelctor('#dateDebut'))
;
Upvotes: 2
Views: 1118
Reputation: 5572
angular.element(document.querySelctor('#dateDebut')).controller('ngModel')
-- this will give the ngModelController
defined on #dateDebut
element.
Here is the plnkr: http://plnkr.co/edit/qXyxEb2QHyhuRUttNMXn?p=preview
Upvotes: 1