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);
    }
}
vdjkelly
  • 129
  • 11

1 Answers1

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>
Hadi J
  • 16,989
  • 4
  • 36
  • 62