Angularjs modal popup, populate table columns

Coded for this SO question: http://stackoverflow.com/questions/29807422/creating-popup-window-with-form-content-and-then-show-output-in-parent-page-and?

by aman1981

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.0/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.0/angular-ui-router.min.js"></script>
<script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.1.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script src="https://code.angularjs.org/1.6.9/angular-sanitize.min.js"></script>
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<div ng-app="myApp" ng-controller="IndexController">

  <ui-view> </ui-view>
  <div class="container">


    <div class="panel panel-default data-table">
      <div class="panel-heading">
        <table class="table table-bordered margin-top-15" ng-form="form">
          <thead>
            <tr class="actions row-border">
              <th class="hidden-border"></th>
              <th ng-repeat="c in targetTable.columns track by $index">
                <span class="span-action">
					<a class="btn btn-xs"><i class="fa fa-times-circle" aria-hidden="true"></i></a>
				</span>
              </th>
            </tr>
            <tr>
              <th>ID #</th>
              <th ng-repeat="c in targetTable.columns" ng-model="c.label">{{c.refColName}} <br /> <span class="col-font-header"> {{c.refInputOperator}} {{c.refColType}} </span></th>
              <th class="comment-fixed-width" ng-model="c.idComment">ID Comment</th>
              <td class="center add-column fixed-width"></td>
            </tr>
          </thead>
          <tbody>
            <tr ng-repeat="r in targetTable.rows">
              <td class="fixed-width">
                <span>
					<a class="btn-xs" ng-show="row == $index" ng-if="targetTable.rows.length > 1"><i class="fa fa-times-circle" aria-hidden="true"></i></a>
				</span>
                <span contenteditable="true" ng-model="r.tableId" ng-change="addNewRow(r.tableId, r)">{{r.tableId}}</span>
             ...

JavaScript

var app = angular.module('myApp', ['ui.router', 'ui.bootstrap', 'ngSanitize']);

app.controller("IndexController", ['$location', '$state', '$scope', '$http', function($location, $state, $scope, $http) {

  //Start: Initialize table - Following is used to setup the UI table and setup its rows and columns
  $scope.createTable = function(tableCounter, currentTableId) {
    $scope.tableCounter++;
    return {
      id: currentTableId++,
      tableName: '',
      columns: [],
      rows: [{}],
      uniqueIdCounter: 1
    }
  }
  $scope.initializeTable = function(isEdit) {
    $scope.tableCounter = 0;
    var currentTableId = 0;
    var table = {
      id: 0,
      tableName: "",
      columns: [],
      rows: [{}]
    };

    $scope.tables = [table];
    $scope.targetTable = $scope.tables[0];
    $scope.tables = [];
    $scope.targetTable = null;
    $scope.isUpdating = false;
    $scope.showColumns = isEdit ? true : false;
    $scope.tables.push($scope.createTable($scope.tableCounter, currentTableId));

    // set the newly create table as active
    $scope.targetTable = $scope.tables[$scope.tableCounter - 1];
  }
  //End initializing table

  //Read json from the API
  $http.get('https://api.myjson.com/bins/d1ugw').success(function(data) {
    if (data.length > 0) {
      $scope.setJson = data;
      $scope.initializeTable(true);
      var columns = $scope.targetTable.columns;

      //These are the 3 columns of the Table but can vary dynamically(currently just hardcoding it)
      var refColName = "state, month , year";

      //Push the columns to the table array
      var colArray = refColName.split(',');
      for (var i = 0; i < colArray.length; i++) {
        $scope.targetTable.columns.push({
          id: columns.length,
          refColName: refColName.split(',')[i]
        });
      }

      //Read the values from the json
      var idValues = $scope.getTableValues($scope.setJson, 'id');
      var commentValues = $scope.getTableValues($scope.setJson,...