Hi everyone I'm learning angular i wrote a simple app but i don't know how i can update the model or the view ,later of get http json.
angular.module("dataApp",[])
.controller("ctrlData",function($scope,$http){
$http.get('consulta.php')
.success(function(data){
//console.log(data);
$scope.personas = data;
}).error(function(error){
console.log(error);
}); });//end ctrl
output of consulta.php
[
{
"id_persona":"1",
"nombre":"sebastian",
"apellido":"rincon ",
"telefono":"4422404",
"direccion":"calle 93 # 23 2132"
},
{
"id_persona":"2",
"nombre":"leiton",
"apellido":"aricapa",
"telefono":"4421112313",
"direccion":"calle 634 supia avenia 93"
},
{
"id_persona":"3",
"nombre":"daniel",
"apellido":"desconocido",
"telefono":"645452423",
"direccion":"urbanizacion los vientos 123"
},
{
"id_persona":"4",
"nombre":"angularjs",
"apellido":"javascript",
"telefono":"0231391",
"direccion":"module controller 321"
},
{
"id_persona":"5",
"nombre":"mark",
"apellido":"zuckerberg",
"telefono":"423423423",
"direccion":"palo alto california"
}
]
index.html
<tr ng-repeat="persona in personas">
<td>{{persona.id_persona}}</td>
<td>{{persona.nombre}}</td>
<td>{{persona.apellido}}</td>
<td>{{persona.telefono}}</td>
<td>{{persona.direccion}}</td>
</tr>
Everything works well but if I insert a new row in the database mysql angularjs will dont know it, i need refresh the page for view the new row. For other hand i tried setTimeout function
setTimeout(function(){
$http.get('consulta.php')
.success(function(data){
console.log(data);
$scope.personas = data;
}).error(function(error){
console.log(error);
});
},1000);
but i think that is not is the correct!. please help thanks.