Http://www.cnblogs.com/ilovewindy/p/3849428.html
<! DOCTYPE html>"Utf-8"> <title></title> <script src="Http://code.jquery.com/jquery.js"></script> <script src="Js/angular/angular.min.js"></script> <script src="Sendsafemessagecontroller.js"></script> "Ftitapp"> <divclass="Form-group"Ng-controller="Sendsafemessagecontroller"> <labelclass="col-md-2 Control-label"> Reply Content:</label> <divclass="col-md-10"> <div ng-repeat="reply in Fchat.replies"> <divclass="Form-group"> <divclass="col-md-12"> <divclass="col-md-1"> <label for="reply{{$index + 1}}"> Answer {{$index +1}}</label> </div> <divclass="col-md-9"> <input type="text" class="Form-control"Ng-model="Reply.value"ID="reply{{$index + 1}}"Name="reply{{$index + 1}}"/> </div> <divclass="col-md-2 Img-link"> <a href=""ng-click="fchat.incrreply ($index)"> "Img/plus.png"alt="Plus"Width="30px"height="30px"/> </a> <a href=""ng-click="fchat.decrreply ($index)"ng-show="fchat.candescreply"> "Img/minus.png"alt="minus"Width="30px"height="30px"/> </a> </div> </div> </div> </div> <input type ="Hidden"Id="Replies"Name="Replies"Value="{{fchat.combinereplies ()}}"/> </div></div> </body>
The Sendsafemessagecontroller.js code is as follows:
varFtitappmodule = Angular.module ('Ftitapp', []); Ftitappmodule.controller ('Sendsafemessagecontroller', function ($scope, $log) {$scope. Fchat=NewObject (); $scope. Fchat.replies= [{key:0, Value:""}]; //the deletion is not allowed because there are only 1 replies at the time of initialization$scope. fchat.candescreply =false; //increase the number of replies$scope. fchat.incrreply =function ($index) {$scope. Fchat.replies.splice ($index+1,0, {key:NewDate (). GetTime (), Value:""});//use timestamps as key for each item//allow deletion after adding a new reply$scope. fchat.candescreply =true; } //reduce the number of replies$scope. fchat.decrreply =function ($index) {//if the number of replies is greater than 1, delete is clicked back if($scope. Fchat.replies.length >1) {$scope. Fchat.replies.splice ($index,1); } //if the number of replies is 1, delete is not allowed if($scope. Fchat.replies.length = =1) {$scope. fchat.candescreply=false; }} $scope. fchat.combinereplies=function () {varCR =""; for(vari =0; I < $scope. fchat.replies.length; i++) {CR+="#"+$scope. Fchat.replies[i].value; } CR= Cr.substring (1); //$log. Debug ("Combined replies:" + CR); returnCR; }});
AngularJS: Implement dynamic Add input control function (GO)