0

I'm trying to implement input validation by angular expression ,I need to do that because i'm going to get validation data from database.

So I'm trying the following code

conttroller

    vm.key="ng-required"
    vm.value="true" 

html

<input  type="text" name="field" ng-model="name" {{vm.key}}="{{vm.value}}" >        

but this make no change.

1
  • Can you update your post with how the (meta-)data about the validation rules would look like? I feel this is a proper case for model validation (in contrast to UI validation) with something like egkyron. If you provided more details, I could set up a fiddle. Commented Jun 28, 2016 at 15:36

1 Answer 1

2

You can't use {{}} directive to create attribute dynamically(it will not work), and I don't think so that would be correct approach to do it. I'd like to suggest slight different way to deal with such validation, like you could take use of angular inbuilt directive like ng-minlength, ng-maxlength, ng-required, etc. which does take expression as their attribute values.

like for case it would be something like

ng-required="vm.value"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.