0

I have a form where there are many inputs fields type="text" and I would need some of the inputs where its value should be populated using clickevent. So I gave a classname for specific inputs which is specialinputs.

       Below is the input field
       <input type="text" class="specialinputs" ngvalue="DataFields1" 
        ngmodel="DataFields1"> 
       </input>

        Below is the javascript code
        var myinputs = document.getElementsByClassName("specialinputs")
        for (i = 0; i < myinputs.length; i++) {
         myinputs[i].value = "Mytext"; 
         }

This works,Mytext is being populated. but my input field ng-model is not getting updated, when i save the form , the values are not getting saved. Iam using angularjs

1 Answer 1

0

it's because angular scope don't know about your changes so you need to tell him about them

var myinputs = document.getElementsByClassName("specialinputs")
    for (i = 0; i < myinputs.length; i++) {
     myinputs[i].value = "Mytext"; 
    }
$scope.$apply();
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.