AngularJS : Replicate div on click of button

百般思念 提交于 2020-01-17 05:37:10

问题


I want to replicate the text fields(div) present in image every time the user click on '+' button.


回答1:


If I understood your question properly , pls refer the below code .

Template

<div ng-app="myapp" ng-controller="myCtrl">
   <div ng-repeat="item in items">
    <input type="text" placeholder="name">
    <input type="text" placeholder="email">
        <button ng-click="add()">+</button>
        <p>Some text some text some text</p>   
   </div> 
</div>

controller

var app = angular.module('myapp',[]);

app.controller('myCtrl',["$scope",function($scope){

    $scope.items = [{}];

    $scope.add = function(){
       $scope.items.push({});
    }

}]);

refer: https://jsfiddle.net/ftzebggn/



来源:https://stackoverflow.com/questions/33210478/angularjs-replicate-div-on-click-of-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!