1

I need to send the value of a hidden field with ng-value I place the code which I am sending a text content type

<form>
          <div class="comment_it commentupdate">
            <div class="up_img">
              <img src="" width="35" height="35" />
            </div>
            <div class="comments-text-post-area">
              <input type="hidden" ng-model="c.cid"  ng-value="'{{p.id}}'">
              <textarea class="add-y-comment" ng-model="c.comment" placeholder="Comentar"></textarea>
            </div>

            <div class="comment-post-wall">
              <div class="cancel-comment">


                  <button type="button" name="button" class="mdl-button mdl-js-button mdl-button--raised" id="" rel="">CANCELAR</button>

              </div>
              <div class="send-comment">

                    <button type="submit" name="button" class="mdl-button mdl-js-button mdl-button--raised" ng-click="c.addComment()">ENVIAR</button>

              </div>
            </div>

          </div>
        </form>

In the console Chrome only captures me the written text in the textarea. p.id is the value of post to comment

angular .module('apiFromApp')

.controller('CommentController', CommentController);

CommentController.$inject = ['$http'];

/* @ngInject */
function CommentController($http) {
    var self = this;

    //sendComment();

    self.addComment = function() {
      console.log(self.cid);
    }
}
2
  • What is c.cid? I guess it's comment_id, correct? Commented May 10, 2016 at 10:55
  • have a look at this stackoverflow.com/a/18446730/1054978 , it addresses the same problem Commented May 10, 2016 at 11:01

1 Answer 1

1

try this

  <input type="hidden" ng-model="c.cid"  ng-value="c.cid = p.id">

var app = angular.module("app",[]);

app.controller("MyCtrl" , function($scope){
  
  $scope.pid = 4;
  $scope.addComment = function(){
    alert($scope.cid);
    }
  
  });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="MyCtrl">
   
  <input type="hidden" ng-model="cid"  ng-value="cid = pid">
  <button type="submit" name="button" ng-click="addComment()">ENVIAR</button>
  
</div>

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.