0

i am using the same form to edit many records existing in an ng-repeat. When I click the edit buttom, i just do the following:

$('#EvaluationQuestionId').val($scope.data.EvaluationQuestion[$index].id);

$('#EvaluationQuestionEvaluationTopicId').val($scope.data.EvaluationQuestion[$index].evaluation_topic_id);

$('#EvaluationQuestionName').val($scope.data.EvaluationQuestion[$index].name);

The form inputs are filled correctly but i do not understand why, the AngularJs model is not updated as it does when you type in those inputs manually and invalid tags are kept until you write anything or select another choice in the populated select input.

I have tryed

$scope.$apply();

and also before the form...

$scope.evaluationFormQuestions.$setPristine(true);

But i am out of energy and ideas already...

1
  • In angular, you modify the model, and allow the digest cycle that gets triggered afterwards to update the view. In your post, you're using jquery to update the view directly. That's bad practice in the angular world. Commented Aug 7, 2014 at 9:29

1 Answer 1

0

Ok, i have updated the code, and as pixelbits suggested, i entered the data directly to the model instead of the inputs. It works and the code is much more easy and shorter.

So... lesson learned: read all the docs before... :)

https://docs.angularjs.org/guide/forms

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.