0

I have hidden input in template HTML:

<input type="hidden" name="idNote" value="{{formSpam.idNote}}" ng-model="formSpam.idNote" required>

Also method in controller that takes one param and assigns this value to formSpam.idNote:

$scope.ClickSpam = function (id){
      $scope.formSpam.idNote = id;
}

But in template for attribute value this is empty when I send form. Why?

Completed code:

<div class="spam-icon ng-scope" data-dismiss="modal" ng-controller="SpamController" ng-click="ClickSpam(22, 1);" data-toggle="modal" data-target="#spamModal"></div>

After this HTML in bottom page:

<div class="modal fade spam-modal" id="spamModal" ng-controller="SpamController" tabindex="-1" role="dialog" aria-hidden="true">
<input type="hidden" name="idNote" ng-value="formSpam.idNote" ng-model="formSpam.idNote" required>
</div>
2
  • Typically, in a Single Page Application, one does not need to use <input type="hidden">, because classic form submission is not done, and instead Ajax is used. But otherwise, value="{{formSpan.idNote}}" should work fine - so, something else is not working in your code Commented Mar 31, 2015 at 6:33
  • Does anybody know solution? Commented Mar 31, 2015 at 7:28

1 Answer 1

5

Use ng-value:-

<input type="hidden" name="idNote" ng-value="formSpam.idNote" ng-model="formSpam.idNote" required>

One more thing there is no need of required and ng-model on hidden field you can simply do it by:-

<input type="hidden" name="idNote" ng-value="formSpam.idNote">

$scope.ClickSpam = function (id){
      $scope.formSpam.idNote = id;
}

Fiddle

Sign up to request clarification or add additional context in comments.

1 Comment

Hm, does not work, so maybe reason is that I have two same controllers? One SpamController in main template and SpamController in modal window?

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.