var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
$scope.obj = {};
$scope.tableRows = [
{
'inputToChange' : 40
},
{
'inputToChange' : 53
},
{
'inputToChange' : 15
},
{
'inputToChange' : 65
},
{
'inputToChange' : 5
},
{
'inputToChange' : 20
},
{
'inputToChange' : 62
},
{
'inputToChange' : 54
},
{
'inputToChange' : 495
},
{
'inputToChange' : 35
}
];
$scope.pasteFunction = function(ev, startIndex) {
console.log(ev);
var text = ev.clipboardData.getData('text');
$scope.inputArray = [];
if(text.indexOf('\n') !== -1) {
// console.log('splitting on newline');
$scope.inputArray = text.split('\n').map(Number);
} else if(text.indexOf('\t') !== -1) {
// console.log('splitting on tab');
$scope.inputArray = text.split('\t').map(Number);
} else if(text.indexOf(',') !== -1) {
// console.log('splitting on ,');
$scope.inputArray = text.split(',').map(Number);
} else if(text.indexOf(' ') !== -1) {
// console.log('splitting on space');
$scope.inputArray = text.split(' ').map(Number);
} else if(text.indexOf('\r') !== -1) {
// console.log('splitting on return');
$scope.inputArray = text.split('\r').map(Number);
}
console.log($scope.inputArray);
// ITERATE THROUGH ITEMS IN table rows that are gonna change
for(i = startIndex; i < $scope.inputArray.length + startIndex; i++) {
// move data element into input field(s)
console.log(ev.target.value);
$scope.tableRows[i].inputToChange = $scope.inputArray[i - startIndex];
console.log($scope.tableRows[i].inputToChange);
// feel free to try messing with this operation to get it to change (GL LOL)
// var elementId = 'inputToChange' + startIndex;
// document.getElementById(elementId).value = $scope.inputArray[i - startIndex];
}
}
});
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link href="style.css" rel="stylesheet" />
<script src="https://code.angularjs.org/1.5.4/angular.js"></script>
<!-- By setting the version to snapshot (available for all modules), you can test with the latest master version -->
<!--<script src="https://code.angularjs.org/snapshot/angular.js"></script>-->
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<table>
<thead>
<tr>
<th>
Input To Change
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in tableRows">
<td>
<input ng-model="row.inputToChange" ng-paste="pasteFunction($event, $index)"
ng-attr-id="{{'inputToChange' + $index}}">
</td>
</tr>
</tbody>
</table>
</body>
</html>
/* Put your css in here */