2016-08-02 81 views
0

我有我的HTML这样的事情,唯一NG绑定,HTML在NG-重复

<div ng-controller='gridDataController as gridDataCtrl'> 
<table> 
    <tbody> 
     <tr ng-repeat="row in gridData" id="{{row.record_no}}"> 
      <td ng-bind-html="editInputA">{{row.a}}</td> 
      <td ng-bind-html="editInputB">{{row.b}}</td> 
      <td> 
       <div> 
        <button ng-click="edit(row.record_no)" >edit</button> 
        <button ng-click="update(row.record_no)" >update</button> 
        <button ng-click="delete(row.record_no)" >delete</button> 
       </div> 
      </td> 
     </tr> 
    </tbody> 
</table> 

我想编辑功能输入框添加到一个特定的行编辑按钮被点击,是否有任何角度做这件事,也是我虽然我希望添加输入框有一个唯一的ID,所以我可以触发它来更新编辑的文本。我正在寻找最好的角度练习,因为我是新手。感谢提前:)

回答

0

做到这一点的最好的办法就是隐藏输入并显示与ngShow(https://docs.angularjs.org/api/ng/directive/ngShow

<body ng-app="ngAnimate"> 
    <button ng-click="showInput= !showInput" >edit</button> 
    <div> 
     <div class="check-element animate-show" ng-show="showInput"> 
     <input class="glyphicon glyphicon-thumbs-up" id="newInput"> 
     </div> 
    </div> 
</body> 

我adaped的例子从ngShow您与ngClick使用它:

https://plnkr.co/edit/Cgo5bFgNxhJUVbTwjzu8?p=preview

的另一种方法将是使用
VAR输入= VAR元素=使用document.createElement( “输入”);

但使用ng-show似乎更适合您的需求