AngularJS : Replicate div on click of button

2019-09-10 21:10发布

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

1条回答
男人必须洒脱
2楼-- · 2019-09-10 22:04

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/

查看更多
登录 后发表回答