【发布时间】:2018-03-26 13:17:17
【问题描述】:
我从我的 mysql 数据库中调用一个带有角度的 http.get(url) 的信息,最后用该信息填充一个表。
这是可行的,但现在我希望控制器在数据库发生更改时自动调用 http.get(url) 而无需手动刷新页面。
评论或提示很受欢迎 :D (我是 Angular 的新手)。
这是我目前的代码:
数据.js
angular.module('demo', [])
.controller('Hello', function($scope, $http, $timeout) {
$scope.loadData = function(){
$http.get('http://localhost:8888/nuevo/respuesta.php').
then(function(response) {
$scope.greeting = response.data;
//console.log($scope.greeting);
//console.log("hola");
});
};//se cierra la funcion
$scope.loadData();
});
index.html
<div ng-controller="Hello">
<table>
<tr>
<th>ID</th>
<th>Banda</th>
<th>Cancion</th>
</tr>
<tr ng-repeat="x in greeting">
<td>{{x.`enter code here`IdCancion}}</td>
<td>{{x.Bandas_Musicales}}</td>
<td>{{x.Canciones}}</td>
</tr>
</table>
<button ng-click="loadData()">reload</button>
</div>
【问题讨论】:
-
显示一些代码。它会增加您获得帮助的机会。
-
哦,对不起,给你。