我已经远离编码已有4年了,现在我正在重新学习使用PHP 7和AngularJs进行编程。我构建了一个简单的CRUD应用程序来研究一些概念,并且我有一个简单的表来显示数据库中的记录,到目前为止,我已经设法对表进行了排序,并且工作正常。问题是,我通过用ng-init调用函数来填充表,它会很好地加载该函数,但是问题是,当我在表上方的TextBoxes上键入以插入新Record时,它会一直在整理表下面。而且我已经用谷歌搜索它了,但是找不到我的问题的答案。希望可以有人帮帮我。
<body >
<div class="container">
<div class="row text-center">
<h1>BANCO PHP - CADASTRO DE CLIENTES</h1>
<hr>
</div>
<div ng-app="myApp" ng-controller="cntrl" ng-init="showclientes()">
<div class="row container">
<div class="col-md-8">
<form class="form-inline">
<div class="form-group">
<label for="id">Id</label>
<input type="text" class="form-control" placeholder="Id" id="id" ng-model="id" disabled>
</div>
<div class="form-group">
<label for="nome">Nome</label>
<input type="text" class="form-control" placeholder="Nome" id="nome" ng-model="nome">
</div>
<div class="form-group">
<label for="saldo">Saldo</label>
<input type="text" class="form-control" placeholder="Saldo" id="saldo" ng-model="saldo">
</div>
<input type="submit" class="btn btn-default" value="{{nomebotao}}" ng-click="insertdata()">
</form>
</div>
<div class="col-md-4"><label class="bg-success">{{msg}}</label>
</div>
</div> <!-- div row form -->
<div class="row container">
<hr>
<h3>RESULTADOS</h3>
<hr>
</div>
<div class="row col-md-6">
<table class="table">
<thead>
<tr>
<th><a href="#" ng-click="tipoOrdem = 'id*1'">Id<span ng-show="tipoOrdem == 'id'; ordemReversa = !ordemReversa" class="fa fa-caret-down"></span>
</a></th>
<th><a href="#" ng-click="tipoOrdem = 'nome'">Nome<span ng-show="tipoOrdem == 'nome'; ordemReversa = !ordemReversa" class="fa fa-caret-down"></span>
</a></th>
<th><a href="#" ng-click="tipoOrdem = 'saldo'">Saldo<span ng-show="tipoOrdem == 'saldo'; ordemReversa = !ordemReversa" class="fa fa-caret-down"></span>
</a></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="cliente in data | orderBy:tipoOrdem:ordemReversa">
<td>{{cliente.id}}</td>
<td>{{cliente.nome}}</td>
<td>{{cliente.saldo}}</td>
<td><button ng-click="deletecliente(cliente.id)" class="btn btn-danger fa fa-trash-o fa-lg"></button>
<td><button ng-click="updatecliente(cliente.id, cliente.nome, cliente.saldo)" class="btn btn-primary fa fa-edit fa-lg"></button>
</tr>
</tbody>
</table>
</div> <!-- div row table -->
</div> <!-- div controler -->
</div> <!-- div main container -->
<!-- javascript funcoes -->
<script>
var app=angular.module('myApp', []);
app.controller('cntrl', function($scope, $http){
$scope.tipoOrdem = 'id*1';
$scope.ordemReversa = false;
$scope.nomebotao="Salvar";
$scope.insertdata=function(){
$http.post("insert.php", {'id':$scope.id, 'nome':$scope.nome, 'saldo':$scope.saldo, 'botao':$scope.nomebotao})
.success(function(){
$scope.msg= "Data Saved";
$scope.showclientes();
});
}
$scope.showclientes=function(){
$http.get("select.php")
.success(function(data){
$scope.data=data
});
}
$scope.deletecliente=function(id){
$http.post("delete.php", {'id':id})
.success(function(){
$scope.msg="Registro excluído.";
$scope.showclientes();
});
}
$scope.updatecliente=function(id,nome,saldo){
$scope.id=id;
$scope.nome=nome;
$scope.saldo=saldo;
$scope.nomebotao="Atualizar";
}
});
</script>
</body>
最佳答案
我只能通过此sort
链接发现一个问题,该问题将自己置于无限循环中,从而导致$rootScope:infdig ..像这样更新它们。
<th><a href="#" ng-click="tipoOrdem = 'id';ordemReversa = !ordemReversa">Id<span ng-show="tipoOrdem == 'id' && ordemReversa" class="fa fa-caret-down"></span>
</a></th>
<th><a href="#" ng-click="tipoOrdem = 'nome';ordemReversa = !ordemReversa">Nome<span ng-show="tipoOrdem == 'nome' && ordemReversa" class="fa fa-caret-down"></span>
</a></th>
<th><a href="#" ng-click="tipoOrdem = 'saldo';ordemReversa = !ordemReversa">Saldo<span ng-show="tipoOrdem == 'nome' && ordemReversa" class="fa fa-caret-down"></span>
</a></th>