I have been working on this project for a while now and wrote some test scripts. I am using setInterval to update the content every 500 seconds, but I am facing an issue with accessing the input fields. For example, if there is a form with input fields, I am unable to write in them as my input gets deleted automatically. The reason I am using setInterval is because I want to continuously see real-time inputs from the database.
Here is the index script:
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
<ul>
<li ng-repeat="x in myData">
<a href="http://php.net/manual/ro/function.json-encode.php"> {{ x.Name + ', ' + x.Country }}</a><input type="text" />
</li>
</ul>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
setInterval(function(){$http.get("customers.json").then(function (response) {
$scope.myData = response.data.records;
});},500);
});
</script>
</body>
</html>
And here is the JSON file:
{
"records": [
{
"Name": "Alfreds Futterkiste",
"City": "Berlin",
"Country": "Germany"
},
{
"Name": "Ana Trujillo Emparedados y helados",
"City": "México D.F.",
"Country": "Mexico"
},
...
// More records continue below
...
{
"Name": "Comércio Mineiro",
"City": "São Paulo",
"Country": "Brazil"
}
]
}