javascript - Pushing values in Ng-model inside ng-repeat -


i trying build status comment type of system using angularjs. first textbox allows user put value in array , display on page. on clicking allows textbox , button enter comment. value of comment not displaying inside scope. code :

html

<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> <script src="status.js"></script> <body ng-app="myapp" ng-controller="userctrl">  <div> <h2>status!</h2> &nbsp;&nbsp;&nbsp;post status here :<br> &nbsp;&nbsp;&nbsp;<textarea rows="5" cols="50" ng-model="value"></textarea> <button ng-click="addstatus()">click add!</button> <br><br><br>     <table>         <tr ng-repeat="add in statushow">                     <td><h3>{{add.value}}</h3>                      <input ng-model="commentvalue" type="text" size="40" placeholder="enter comment here!"></input>                      &nbsp;&nbsp;&nbsp;                      <button ng-click="addcomment()">add comment!</button>                         <table>                         <tr ng-repeat="comms in comments">                         <td><h4>{{comms.commentvalue}}</h4></td></tr></table>                      </td>           </tr>     </table>     {{commentvalue}}     </div> 

status.js

var app = angular.module('myapp', []) app.controller('userctrl', function($scope) {     $scope.statushow = [];     $scope.comments = [];      $scope.addcomment= function(){         $scope.comments.push({             commentvalue: $scope.commentvalue         });         $scope.value="";     };      $scope.addstatus= function(){         $scope.statushow.push({             value: $scope.value         });         $scope.value="";     };  }); 

try http://jsfiddle.net/rrfqaf9l/2/:

<div ng-app="myapp" ng-controller="userctrl">  <h2>status!</h2> &nbsp;&nbsp;&nbsp;post status here : <br>&nbsp;&nbsp;&nbsp; <textarea rows="5" cols="50" ng-model="value"></textarea> <button ng-click="addstatus()">click add!</button> <br> <br> <br> <table>     <tr ng-repeat="add in statushow">         <td>             <h3>{{add.value}}</h3>              <input ng-model="add.commentvalue" type="text" size="40" placeholder="enter comment here!"></input>&nbsp;&nbsp;&nbsp;             <button ng-click="addcomment(add)">add comment!</button>             <table>                 <tr ng-repeat="comms in add.comments">                     <td>                         <h4>{{comms.commentvalue}}</h4>                     </td>                 </tr>             </table>         </td>     </tr> </table>{{commentvalue}}</div> 

javascript:

var app = angular.module('myapp', []) app.controller('userctrl', function($scope) { $scope.statushow = [];  $scope.addcomment= function(add){     if (typeof add.comments == 'undefined') add.comments = [];     add.comments.push({         commentvalue: add.commentvalue     });     add.commentvalue=""; };  $scope.addstatus= function(){     $scope.statushow.push({         value: $scope.value     });     $scope.value=""; };  }); 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -