2017-08-25 56 views
0

我不想在console.log $scope.value中顯示來自輸入的數據,點擊後我選擇了該數字。輸入的數字AngularJS

我的代碼:

<table class="table table-bordered table-striped"> 
         <thead> 
         <tr> 
          <th >Name 
          <th >System 
          </th> 
          <th>Actions</th> 
         </tr> 
         </thead> 
         <tbody> 
         <tr ng-repeat="n in data"> 
          <td style ="word-break:break-all;">{{n.name}}</td> 

          <td style="width:35px;">{{n.system}}</td> 
          <td><input class="form-control input-sm" type="number" name="input" ng-model="value" 
             min="0" max="100" style="width:55px;"> 
           </td> 

         </tr> 
         </tbody> 
        </table> 
        <button ng-click="postapi()">Value</button> 

Plunker:http://plnkr.co/edit/g1t4pludTTIAJYKTToCK?p=preview

感謝答案提前!

+1

爲什麼你想要將數據中的所有元素綁定到'value',而不是將每個元素綁定到它自己的值,比如'ng-model =「n.value」'而不是'ng-模型= 「值」'?用你的方法,你將在'data'中的所有項目具有相同的值 – codtex

回答

1

您不能訪問在ng-repeat中定義的value,因爲ng-repeat會創建它自己的作用域。而我所知道的是,你不能從父範圍訪問子範圍。

如果將ng-model="value"更改爲ng-model="n.value"會更好。然後你可以訪問對象的值