如何使用div模态与ng-repeat

时间:2016-04-29 03:47:07

标签: html angularjs

我想将循环索引传递给函数Createprofile()。我想使用角度控制器来做到这一点。

HTML

<li ng-repeat = "proteam in proteams | filter:filtText | filter:filtText1" ng-init="counter">
<p>{{proteam.description}}</p>
    <div class="modal fade" id="collaborateForm" role="dialog" hidden="true" style="overflow: auto;">
         <div class="modal-dialog">
         <!-- Modal content-->
         <div class="modal-content fade in">
              <div class="modal-header">
                  <button type="button" class="close" data-dismiss="modal">&times;</button>
                      <h4 class="modal-title">COLLABORATION FORM</h4>
              </div>
              <div class="modal-body" >
         <!-- Collaborate FORM -->
                   <form  ng-submit="createProfile(counter)" onkeypress="return event.keyCode != 13;">
                        <label>Enter team Name:</label>
                               <input type="text" class="form-control" id="teamName" required="required">
                                     <button type="submit" class="btn btn-primary btn-xs" dismiss="modal" onClick="turnDivOff()">Collaborate</button>
                   </form>
               </div>
              </div>
              </div>
              </div>                                                
                        </li>

3 个答案:

答案 0 :(得分:0)

你可以在ng-repeat中使用track by

<li ng-repeat = "proteam in proteams | filter:filtText | filter:filtText1 track by $index" ng-init="counter">

然后你可以在ng-repeat

中使用它
<form  ng-submit="createProfile($index)" 

答案 1 :(得分:0)

试试这个

<form  ng-submit="createProfile($index)" onkeypress="return event.keyCode != 13;">

ng-repeat期望一个数组,因此它有一个与之关联的索引

答案 2 :(得分:0)

  

检查以下代码。每次点击都会提醒表单的索引。

&#13;
&#13;
GPKSM2>GPISL1>GPJJR18>GFGTR
&#13;
angular.module('myApp', [])
           .controller('myCtrl',function($scope) {
  $scope.createProfile = function(html) {
    alert(html);
  }
$scope.proteams =[{'description':'stack'}, {'description':'overflow'}]
});
&#13;
&#13;
&#13;