AngularJS: Implementing dynamic Add input control functionality

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.