I'm new to meanjs
, I just created a new module for adding products. These products are displayed in the home page. But the display in home page is not getting updated real time
. I just added new product in one tab, and the products list in the other tab need to be refreshed to see the change. How can this be done at real time
?
Edit:
By updation I meant is, when ever a new record is been added to database, the product display should update in realtime. Now I need to refresh the page to see the newly added product. My code is
Client
$http.get('/latestproducts').
success(function(data, status, headers, config) {
$scope.latestproducts = data;
})
Server
exports.getlatestProducts = function(req, res) {
Product.find().sort('-created').populate('user', 'displayName').exec(function(err, products) {
if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
res.jsonp(products);
}
});
If you mean browser tabs, mean.js won't do if fo you. You can use sockets to inform server that changes were made and then broadcast message to all active tabs to refresh data. You can also try window.blur/window.focus events to reload data.
If you have list of products and product form on the same page, you have 2 options:
add saved item to your local collection after you save poduct and recive success message from server.
Update local collection(get list of objects from the server) after you save poduct and recive success message from server.