S
S
Sergey Romanov2015-01-04 22:06:41
Angular
Sergey Romanov, 2015-01-04 22:06:41

How can I support ngMessage in a directive if the form element is not an input?

I have a form element. This is such a file loader. It's a whole little component. But as a directive.

<div s3 options="options" ng-model="form.files"></div>

Everything works, and I require ngModel in the directive. I can appoint
ngModel.$setValidity('upload', false);
But that's just no use. How will I catch it in ngMessage? because there is something like
<div ng-messages="testForm.upload.$error">
Where upload is the name of the element. But it must be either an input or a select. And I have neither. So I appointed this validation, but how can I catch it now?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-01-05
Protko @Fesor

ngMessages stupidly takes the expression that you feed it.
form registers controls and takes their name from the $name property, which by default is taken from the name attribute .
Conclusion, you can:
- add the name or data-name attribute
- set the name of the control yourself using ngModelController

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question