I am currently in the process of building a social networking application using AngularJS. I have come across an issue regarding data binding. In my app, there is a timeline div where all the recent posts are displayed, along with a status updater at the top. Upon page load, I make an AJAX ($http) call to the database to retrieve all the posts in JSON format and bind them to the div using ng-bind. However, if I update the status, how can I ensure that the updated data is displayed without having to refresh the entire page? I'm struggling with this problem and would appreciate any assistance.
Thank you, Pavan
EDIT## - Some helpful individuals requested for code, so here it is. I am still encountering difficulties in properly binding my JSON data. Your guidance is highly appreciated.
wall.controller('mainData', function($scope, $http)
{
$scope.status = {};
$scope.updatedStatus = {};
$scope.getStatus = function(){
var uid = localStorage.getItem('_id');
$http({
method: "GET",
url: "http://localhost:8000/profile/status/"+uid
}).success(function (data, status, headers, config) {
$scope.updatedStatus =data;
})
}
and the HTML section
<div class="card" ng-controller="mainData" ng-repeat="item in updatedStatus">
<div class="card-header">
<div class="media">
<div class="pull-left">
<img class="lv-img" src="img/profile-pics/2.jpg" alt="">
</div>
<div class="media-body m-t-5">
<h2><a href="profile.html" class="a-title">{{item.firstname+" "+item.lastname}}</a><small>{{item.record_time}}</small></h2>
</div>
</div>
</div>
<hr/>
<div class="card-body card-padding">
<p>{{item.message}} </p>
</div>
</div>
JSON array received from the server
[
{firstname: "Pavan"
id: 1
lastname: "Kumar"
message: "This is my first update"
record_time: "10/16/2015, 8:32:16 PM"},
{firstname: "LOL"
id: 2
lastname: "test"
message: "This is my second update"
record_time: "10/16/2015, 8:32:16 PM"}
]
Despite receiving a valid JSON object from the server, I am unable to display any new values added or existing data. There seem to be issues with the ng-repeat directive. Any help on resolving this matter would be greatly appreciated. :)