我正在使用angularjs。我想要做的是当用户点击按钮时,通过Angularjs检查数据库中的学生ID。 如果学生ID存在于数据库中,将显示#modal1,否则将提示#modal2。是否可以使用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;
}
答案 0 :(得分:1)
在控制器编写代码中
$scope.act = function(g){
/*
write code for check student is in database
*/
if(student_available == true){
$("#modal1").modal('show');
}
else{
$("#modal2").modal('show');
}
}