见这
Plunker
这是您需要的一个例子.正如你可以在plunker中看到的,有一个TextArea可以在按钮点击动态创建.创建的TextAreas也可以通过删除按钮单击来删除.
请参阅下面的HTML
- <div class="col-sm-10">
- <input type="button" class="btn btn-info" ng-click="addNewChoice()" value="ADD QUESTION">
- <div class="col-sm-4">
- <fieldset data-ng-repeat="field in choiceSet.choices track by $index">
- <textarea rows="4" cols="50" ng-model=" choiceSet.choices[$index]"></textarea>
- <button type="button" class="btn btn-default btn-sm" ng-click="removeChoice($index)">
- <span class="glyphicon glyphicon-minus"></span> REMOVE
- </button>
- </fieldset>
- </div>
- </div>
JS将如下
- var app = angular.module('myApp',[]);
- app.controller('inspectionController',function($scope,$http) {
- $scope.choiceSet = {
- choices: []
- };
- $scope.quest = {};
- $scope.choiceSet.choices = [];
- $scope.addNewChoice = function() {
- $scope.choiceSet.choices.push('');
- };
- $scope.removeChoice = function(z) {
- $scope.choiceSet.choices.splice(z,1);
- };
- });