2017-10-14 17 views
0

我打電話從我的mysql數據庫與http.get(url)的角度信息,並最終填充表中的信息。從角度自動從MySQL重新加載表

這是行得通的,但現在我希望控制器在數據庫自動更改時調用http.get(url),而無需手動刷新頁面。

評論或建議很受歡迎:D (我有點新的角度)。

這是我當前的代碼:

data.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> 
+0

顯示一些代碼..它增加了獲得幫助的機率。 –

+0

哦對不起,你走了。 –

回答

1

爲了通知你的數據更改的客戶端,你需要找到服務器上服務器聯繫客戶端的一種方式。一個流行的解決方案是websockets,也許可以查看。此外,一些PHP框架已經爲此做了一些準備。
如果你不想進入websockets,你可以考慮每隔x秒刷新一次表格數據,以保持它的最新狀態。

+0

謝謝你的回答?我會看看websockets :) –