D
D
DarthJS2015-05-25 13:47:18
JavaScript
DarthJS, 2015-05-25 13:47:18

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

4 answer(s)
D
DarthJS, 2015-05-25
@DarthJS

Thanks everyone, decided
Who cares: jsfiddle.net/d3hszefb/1

M
Mikhail Osher, 2015-05-25
@miraage

vitalets.github.io/angular-xeditable

A
Alexey Pavlov, 2015-05-25
@joseperez

<div ng-repeat="item in items">
    <div ng-click="setValue($index)">{{ item.value }}</div>
</div>

$scope.setValue = function (index) {
    $scope.items[index].value = 'x';
}

A
Alexander Tartmin, 2015-05-25
@baskerville42

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 question

Ask a Question

731 491 924 answers to any question