Answer the question
In order to leave comments, you need to log in
How to get and change table cell value using Angular?
There is a table, it is created through ng-repeat, you need to get its value by clicking on the cell and change its value, let's say to "x". How to do it?
Example from the link
Answer the question
In order to leave comments, you need to log in
<div ng-repeat="item in items">
<div ng-click="setValue($index)">{{ item.value }}</div>
</div>
$scope.setValue = function (index) {
$scope.items[index].value = 'x';
}
If I understood correctly, then you needed it, which means you were close to the result by two lines of code =)
var app = angular.module("MyApp", []);
function Game() {
this.foo = function(size) {
this.arr = [];
for (var i = 0; i < size; i++) {
this.arr.push(i);
}
}
this.push = function(parent, index) {
this.sign = 'X';
this.position = parent + ', ' + index;
}
}
<div ng-app="MyApp">
<div ng-controller="Game as ctrl">
<table class="board">
<h1>Table</h1>
<input type="number" ng-model="val">
<button ng-click="ctrl.foo(val)">PRESS</button>
<tr ng-repeat="item in ctrl.arr">
<td ng-repeat="td in ctrl.arr" ng-click="ctrl.push($parent.$index, $index)">{{ctrl.sign}}</td>
</tr>
</table>
<h1> {{ctrl.position}}</h1>
</div>
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question