angular bootstrap

by aman1981

HTML

<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.9.0/ui-bootstrap-tpls.min.js"></script>
<div ng-controller="AccordionDemoCtrl">
  <div class="modal-header">
    <h3 class="modal-title">Define</h3>
  </div>
  <div class="modal-body" style="height: 400px;overflow-x: auto;">
    <form role="form" name="paramForm" novalidate class="form-body">
      <table class="table table-borderless" ng-if="options.length>0">
        <thead>
          <tr>
            <td class="bold">Key</td>
            <td class="bold">Value</td>
          </tr>
        </thead>
        <tbody style="border: none;">
          <tr ng-repeat="m in options">
            <td ng-class="{ 'has-error': paramForm['ctrlKey_' + {{$index}}].$invalid && (paramForm['ctrlValue_' + {{$index}}].$touched || paramForm.$submitted) }">
              <input type="text" name="ctrlKey_{{$index}}" class="form-control" ng-model="m.optionText" required />
            </td>
            <td>
              <input type="text" class="form-control" ng-model="m.optionValue" required />
            </td>
            <td>
              <a class="btn btn-xs" ng-click="Remove($index)"><i class="glyphicon glyphicon-trash"></i></a>
            </td>
          </tr>
        </tbody>
      </table>
      <div style="margin-left:5px">
        <button class="btn btn-primary btn-sm" ng-click="Add()"><i class="fa fa-plus"></i> Add</button>

      </div>
    </form>
  </div>
  <div class="modal-footer">
    <button class="btn btn-default" type="button" ng-click="cancel()">Cancel</button>
    <button class="btn btn-primary" type="button" ng-click="done(paramForm.$valid)">Done</button>
  </div>




</div>

JavaScript

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

function AccordionDemoCtrl($scope) {

  $scope.options = [];

  $scope.addOptions = function() {
    $scope.options.push({});
  };
  $scope.options = [];

  $scope.Add = function() {
    //Add the new item to the Array.
    var option = {};
    option.Name = $scope.Name;
    option.Country = $scope.Country;
    $scope.options.push(option);

    //Clear the TextBoxes.
    $scope.Name = "";
    $scope.Country = "";
  };

  $scope.Remove = function(index) {
    //Find the record using Index from Array.
    var name = $scope.options[index].Name;
    $scope.options.splice(index, 1);
  };

  $scope.done = function(isValid) {
    $scope.submitted = true;
    if (isValid) {
      alert('Valid');

    } else {
      alert('Invalid');
    }
  };

}