2016-06-10 110 views
0

我的問題在ng-repeat values with 3 columns in table? - AngularJS獲取按鈕值時點擊Angularjs

與此相關的問題。然後我的問題是如何獲取有關點擊該按鈕的價值。 ?

這裏是我的問題

<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> 

它可以在一個單一的陣列。但在多個它不是

+0

這應該工作.. cjmling

+0

Neithe問題或其接受的答案中都沒有任何按鈕。這也是不清楚你的意思是「按鈕價值」。所以我不知道你在問什麼。在你自己的問題中解釋你想要達到的目標,並顯示你所嘗試的代碼。 –

+0

「ng-repeat =」列中的行'' – ihemant360

回答

1

你可以嘗試這樣的事情。

<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) }; 
}); 
+0

對我有用,謝謝 –

-2

//假設這是你的陣列

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

//使用NG-重複顯示所有數據

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

然後傳遞到控制器,有獲得的價值。

+0

列是一個對象:只需寫ng-click =「somefunction(column)」 – Silvinus