ng-value不提交正确的值

时间:2016-06-22 12:52:34

标签: angularjs

这是我的观点

div class="mdl-cell--12-col  chat__list" >
  <div class="mdl-cell--12-col" ng-repeat="listRoom in itemsList  track by $index">
    <ul>
   Channel name : {{listRoom[0]}}
      <li ng-repeat="x in listRoom[1]" >
         <p>MESSAGE : {{x.message_text}}
        </div>
      </li>
    </ul>
    <form name="haha{{$index}}">
      <input type="hidden" type="text"  ng-model="item.admin_id" />
      <input type="hidden"  type="text" ng-value="item.channel_name = listRoom[0]" ng-model="item.channel_name "/>
      <textarea ng-keydown="$event.which === 13 && addRoom()" placeholder="Type Your Message Here" ng-model="item.message_text"></textarea>
      <button  class="send__chat col-lg-2 pull-right" ng-click="addRoom()">Send</button>
       {{item | json }}
  </form>
 </div>

这是我的控制器的例子

$scope.itemsList =[{
    "blp-crdtcrd-46": {
        "message_text": "hai",

    },
    "blp-crdtcrd-47": {
        "message_text": "halo",

    }, "blp-crdtcrd-48": {
        "message_text": "what",

    },
}];
$scope.item={};
$scope.addRoom = function(){
       $scope.item.admin_id = 1;
       $scope.item.user_id = 0;
       chatService.AddChat($scope.item);
}

我的问题是每次提交表单时,item.channel_name的ng值始终提交blp-crdtcrd-48而不是动态,我的数组中有3个通道,并且它总是提交blp-crdtcrd-48。我正在使用{{item | json}}在提交前显示ng值并显示相关值,当我点击提交按钮时,值结果总是blp-crdtcrd-48

帮助我,我非常感谢你的评论和帮助非常感谢

0 个答案:

没有答案