Note that there are some explanatory texts on larger screens.

plurals
  1. POPass some properties to a directive in AngularJS
    text
    copied!<p>I created a directive (itcValidationMessages) which will let me display a validations messages and I put it on the form element as an attribute like below:</p> <pre><code>&lt;form id="register-form" novalidate ng-submit="register()" itc-validation-messages ... </code></pre> <p>Directive that I mentioned above, iterates through all of input elements within the form and displays the error messages if anyone has an invalid state. </p> <p>I store a validation messages in the separate file (because there can be a lot of them and I want to be prepare for i8n so I've separated them from directive) like this: </p> <pre><code>angular.module('models.ValidationMessages', []).constant("ValidationMessages", { validationMessages: { required: 'Value is required!', email: 'You should enter a valid email address!', minlength: 'Enter more characters!', maxlength: 'You have entered to many characters!' } </code></pre> <p>});</p> <p>Is it a correct way to put those messages in constant?</p> <p>I have a default message for each validator, but I want to let to add a custom messages for each input e.g.:</p> <pre><code>&lt;input type="password" minlength-message="Your password should has at least 3 characters" </code></pre> <p>What is a the best way to do it? Because why I use an attribute like above (minlength-message) I cannot get access to it from my directive without using <code>$observe</code>. I don't want to declare one object and put those custom messages in one place, because I should then add to each of message an input name to recognize for which input them belong. So I try to find some convenient and according to art solution.</p> <p>I don't need an isolated scope in the itcValidationMessages directive and I don't want a separate directive for each validator like minlengthMessage to pass specific validation message to my directive which should display this message (itcValidationMessages).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload