I was able to successfully loop through a table using AngularJS to retrieve values from a specified scope named {{rec}} as shown below.
HTML
<div id="AngularContainer" data-ng-app="myApp" data-ng-controller="myCtrl">
<a data-ng-click='<%# "ShowFiles("+ Eval("FilesNames") + ")" %>' style="cursor: pointer">
<table id="fils" style="display:none;">
<thead>
<tr>
<td>File Name</td>
<td>Designation</td>
</tr>
</thead>
<tr data-ng-repeat="rec in records">
<td style="border: 1px solid #000000">{{rec}}</td>
// The values here are displayed successfully when button #Second is pressed, because there is a scope named {{rec}}
<td style="border: 1px solid #000000">
<input data-ng-model="naming" type="text" style="width: 200px" />
// However, the values do not display when I press button #Second, because (data-ng-model="naming") that scope is not related to {{rec}}
</td>
</tr>
<tfoot>
<tr>
<td colspan="2" style="text-align: center">
<input id="Second" data-ng-click="dothat()" class="sav" type="button" value="Save" />
</td>
</tr>
</tfoot>
</table>
<div id="fnalmsg"></div>
</div>
Angularjs
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function ($scope) {
$scope.ShowFiles = function (elm) {
$scope.records = elm;
};
$scope.dothat = function () {
var msg = document.getElementById("fnalmsg");
var index = 0;
$scope.records.forEach(function (rec, naming) {
msg.innerHTML =
msg.innerHTML + 'row #' + (index++) + ': ' + JSON.stringify(rec) + ' --- ' + naming + '<br />';
});
};
});
</script>
However, I encountered an issue with looping through an undefined scope named (data-ng-model="naming") which is meant to store values.
The final output appeared as follows:
row #0: "WIN_20170226_191746.JPG" --- 0
row #1: "WIN_20170226_191848.JPG" --- 1
row #2: "WIN_20170226_191908.JPG" --- 2
The expected output should be like this:
row #0: "WIN_20170226_191746.JPG" --- "Friends"
row #1: "WIN_20170226_191848.JPG" --- "Animals"
row #2: "WIN_20170226_191908.JPG" --- "Cars"
In simpler terms: How can I make (data-ng-model="naming") display names like "Friends","Animals","Cars" as entered in the ng-model="naming" inputs rather than showing unwanted values like 0,1,2 ?