2015-02-10 15 views
-1

我正在使用angularjs。我想要做的是當用戶點擊一個按鈕時,通過Angularjs檢查數據庫中的學生ID。 如果數據庫中存在student id,則會顯示#modal1,否則會提示#modal2。有沒有可能用angularjs做到這一點?如果可能的話如何..顯示多個模式在angularjs中彈出

的Html

<tr ng-repeat="g in students"> 
    <td>{{g.studentId}}</td> 
    <td>{{g.studentName}}</td> 
    <td> 
    <div class="btn-group" role="group" aria-label="btnActions"> 
     <button type="button" ng-click="act(g)" title="act" data-toggle="modal" data-target="#deleteModal"></button>  
    </div> 
    </td> 
</tr> 

#Modal that will be displayed 
<!-- modal1 --> 
<div class="modal fade" id="modal1" role="dialog"> 
    <div class="modal-dialog"> 
     <div class="modal-content"> 
      <div class="modal-body"> 
       confirm delete? 
      </div> 
      <div class="modal-footer"> 
       <button type="button" class="btn btn-primary" ng-click="delete()">Yes</button> 
       <button type="button" class="btn btn-default" > No</button> 
      </div> 
     </div> 
    </div> 
</div> 

<!-- modal2 --> 
<div class="modal fade" id="modal2" role="dialog"> 
    <div class="modal-dialog"> 
     <div class="modal-content"> 
      <div class="modal-body"> 
       Data already existed 
      </div> 
     </div> 
    </div> 
</div> 

控制器

$scope.act = function (g) { 
    g.studentId; 
} 

回答

1

在控制器寫代碼

$scope.act = function(g){ 
    /* 
     write code for check student is in database 
    */ 
    if(student_available == true){ 
     $("#modal1").modal('show'); 
    } 
    else{ 
     $("#modal2").modal('show'); 
    } 
} 
+0

對不起,該代碼的變化不大。 – digit 2015-02-10 04:22:46

+0

ok2。我想嘗試一下。 – digit 2015-02-10 04:25:52

+0

它的工作。謝謝 – digit 2015-02-10 04:36:22