2016-04-29 1 views
3

Я хочу передать индекс цикла функции Createprofile(). Я хочу сделать это с помощью углового контроллера.Как использовать div modal с ng-repeat

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> 

ответ

0

вы можете использовать отслеживать путем в нг-повторе

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

, то вы можете использовать его внутри нг-повторить

<form ng-submit="createProfile($index)" 
+0

Это ошибка, когда я использую след 'code' angular.js : 12722Error: [filter: notarray] http://errors.angularjs.org/1.4.9/filter/notarray?p0=0 при ошибке (родной) по адресу http: // localhost: 8080/bower_components/angular/angular.min.js: 6: 416 –

+0

о, извините, трек по индексу $ должен быть последним. Попробуй это. – ariezona

+0

все еще не работает –

0

Попробуйте это как

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

ng-repeat ожидается массив, так что есть индекс, связанный с ним

+0

Это не работает, так как $ index не может отслеживать. –

0

Check the below code. On every click the index of the form is alerted.

angular.module('myApp', []) 
 
      .controller('myCtrl',function($scope) { 
 
    $scope.createProfile = function(html) { 
 
    alert(html); 
 
    } 
 
$scope.proteams =[{'description':'stack'}, {'description':'overflow'}] 
 
});
<html ng-app="myApp"> 
 
<head> 
 
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
 
</head> 
 
<body ng-controller="myCtrl"> 
 
<ul> 
 
<li ng-repeat = "proteam in proteams" ng-init="counter"> 
 
<p>{{proteam.description}}</p> 
 
    <div class="modal fade" id="collaborateForm" role="dialog" 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($index)" 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></ul>

Смежные вопросы