JSFiddle - React, Tailwind, and code Playground

by Stepan Kasyanenko

HTML

<div ng-app="angularjs-starter" ng-controller="MainCtrl">
  <button class="addfields" ng-click="addNewChoice()">Add choice</button>
  <fieldset data-ng-repeat="choice in choicesA">
    <input type="text" ng-model="choice.name" name="" placeholder="Enter name">
    <button class="remove" ng-click="removeChoice($index)">-</button>
    <select type="text" ng-model="choice.resource" name="" ng-options="res as res.nameResource for res in resources track by res.id">
    </select>
  </fieldset>


  <div id="choicesDisplay">
    <pre>choicesA = {{ choicesA }}</pre>
    <pre>resources = {{ resources}}</pre>
  </div>
</div>

CSS

fieldset {
  background: #FCFCFC;
  padding: 16px;
  border: 1px solid #D5D5D5;
}

.addfields {
  margin: 10px 0;
}

#choicesDisplay {
  padding: 10px;
  background: rgb(227, 250, 227);
  border: 1px solid rgb(171, 239, 171);
  color: rgb(9, 56, 9);
}

.remove {
  background: #C76868;
  color: #FFF;
  font-weight: bold;
  font-size: 21px;
  border: 0;
  cursor: pointer;
  display: inline-block;
  padding: 4px 9px;
  vertical-align: top;
  line-height: 100%;
}

input[type="text"],
select {
  padding: 5px;
}

JavaScript

var app = angular.module('angularjs-starter', []);

app.controller('MainCtrl', function($scope) {

  $scope.resources = [{
    id: '1',
    nameResource: "res 1"
  }, {
    id: '2',
    nameResource: "res 2"
  }, {
    id: '3',
    nameResource: "res 3"
  }, {
    id: '4',
    nameResource: "res 4"
  }];

  $scope.choicesA = [{
    id: 'choice1',
    resource: {
      id: '1',
      nameResource: "res 1"
    }
  }, {
    id: 'choice2',
    resource: {
      id: '2',
      nameResource: "res 2"
    }
  }];


  $scope.addNewChoice = function() {
    var newItemNo = $scope.choicesA.length + 1;
    $scope.choicesA.push({
      'id': 'choice' + newItemNo,
      resource: {}
    });
  };

  $scope.removeChoice = function(ind) {
    $scope.choicesA.splice(ind, 1);
  };


});