<!DOCTYPE html>
<html ng-app="dynamicFieldsPlugin">
<head>
<link data-require="bootstrap@3.3.2" data-semver="3.3.2" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<script data-require="bootstrap@3.3.2" data-semver="3.3.2" src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<script data-require="jquery@2.1.3" data-semver="2.1.3" src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
<script data-require="angular.js@1.3.15" data-semver="1.3.15" src="https://code.angularjs.org/1.3.15/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<div ng-controller="dynamicFields" class="container">
<h1>Dynamic Form Fields Creation Plugin</h1>
<div class="form-group" data-ng-repeat="choice in choices">
<label for="choice" ng-show="showChoiceLabel(choice)">Choices</label>
<button ng-show="showAddChoice(choice)" ng-click="addNewChoice()">Add Choice</button>
<button ng-click="removeNewChoice()">Remove Choice</button>
<input type="text" ng-modal="{{choice.name}}" name="" placeholder="Enter a restaurant name" value="{{choice.id}}">
</div>
</div>
<!--jQuery Scripts -->
<script src="app.js"></script>
</body>
</html>
// Code goes here
/* Styles go here */
/**
* Custom AngularJS App File
* for populating and creating
* form fields dynamically
**/
var app = angular.module("dynamicFieldsPlugin", []);
app.controller("dynamicFields", function($scope) {
$scope.choices = [{id: 'choice1', name: 'choice1'}, {id: 'choice2', name: 'choice2'}, {id: 'choice3', name: 'choice3'}];
$scope.addNewChoice = function() {
var newItemNo = $scope.choices.length+1;
$scope.choices.push({'id' : 'choice' + newItemNo, 'name' : 'choice' + newItemNo});
};
$scope.removeNewChoice = function() {
var newItemNo = $scope.choices.length-1;
if ( newItemNo !== 0 ) {
$scope.choices.pop();
}
};
$scope.showAddChoice = function(choice) {
return choice.id === $scope.choices[$scope.choices.length-1].id;
};
});