0

My question Related to this Question at ng-repeat values with 3 columns in table? - AngularJS

Then my Question is How to Get the Value of that button on click. ?

Here is My Problem

 <input type='text' ng-model="mydata" />

  <span ng-bind="$parent.$eval(mydata)"></span> 




 $scope.buttons =[ [0,1,2,3,4],
                    [5,6,7,8,9]
                  ];




<tr ng-repeat="row in buttons">
  <td ng-repeat= "button in row"><button class="btn btn-primary" ng-click ="$parent.mydata = $parent.mydata.toString() + button">
    {{button}}</button></td>
  </tr>

It Works on a single Array. But in multiple it doesn't

4
  • This should work.. <span ng:repeat="(index, value) in array" ng-click="imClicked(value)"> Commented Jun 10, 2016 at 5:46
  • Neither the question nor its accepted answer has any button in it. It's also unclean what you mean with "button value". So I have no idea what you're asking. Explain, in your own question, what you're trying to achieve, and show the code you tried. Commented Jun 10, 2016 at 5:49
  • what about ng-repeat="column in row" Commented Jun 10, 2016 at 5:50
  • Stop using $parent. Call functions on your $scope, and put the code you want to execute in that function. The parent scope of the inner ng-repeat is the scope of the outer ng-repeat, not the scope of the controller. Commented Jun 10, 2016 at 6:00

2 Answers 2

1

You can try something like this.

 <body ng-app="myApp" ng-controller="myCtrl">
    <div ng-repeat="value in array">
            <button ng-click=myFunction(value,$index)> MyButton</button>
    </div>
 </body>

app.controller('myCtrl', function ($scope) {
$scope.myFunction = function(val,index) {
console.log(val) };
});
Sign up to request clarification or add additional context in comments.

Comments

-2

//assuming this is your array

$scope.data = [
    ["opt1", "opt2", "opt3"],
    ["opt1", "opt2", "opt3"],
    ["opt1", "opt2", "opt3"]
];

// using ng-repeat to show all data

<table>
    <tr ng-repeat="row in data">
        <td ng-repeat="column in row" ng-click="somefunction('{{column}}')">{{column}}</td>
    </tr>
</table>

THEN PASS IT TO THE CONTROLLER AND GET THE VALUE THERE..

1 Comment

column is an object: just write ng-click="somefunction(column)"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.