Problems using $interval to create a live feed? - javascript

So i'm just getting into using the MEAN stack and am creating a live feed. I've made an API that basically sends data to my DB. I've then used Angular to create a live feed of the data being sent to the DB.
I'm using $interval in my controller with $http.get() to grab data from my api every .5 seconds.
Is there anything wrong with doing it this way? Is there a better way that a noob like me would be able to understand and implement?

Related

How to sync database and angular component?

I am trying to fetch data continuously from mongo database.
It needs refresh the page in order to get latest data.
My question, Is there any way to put angular service and component which will check & fetch data in real time?
Some of the way which i found in internet such as :
Call the service in setInterval after few seconds.
or, Use of third party fireloop.
But really i don't want these strategy.
Could someone guide me how & where to proceed to achieve real time functionality ?
I am using anuglar v4 and mongodb v3.
Thanks.

Jade #{user.username} Partial Page Refresh

I'm using https://github.com/sahat/hackathon-starter/tree/es6 which leverages Jade in an ExpressJS & MongoDB NodeJS environment. My questions is how can I update #{event.location} && #{event.city} in Front-end if they change inside MongoDB in the back-end?
I do not want to refresh the entire website in order for #{event.location} and #{event.city} to be updated in the front-end.
Could someone please explain how to do this or if there is a better way of achieving this? Maybe with Socket.IO or some other way. I'm fairly new to Node, JS, Jade etc and can't even grasp a decent way of refreshing part of the page with JADE....
Thank you in advance for your help ! Kudos
Express/Jade can only render the page once from backend when the HTTP request comes.
If you have to update the data on frontend, you will have to use different strategy depending on how your data is updated.
If your data in the backend is updated via the same frontend or at known time you can use AJAX calls to server and fetch the values intermittently.
If data is updated via a different channel then socket.io would be the way to go. You can emit events from the backend on data change and receive the events on frontend app and update the data fields only using javascript bindings.
If you have too many manipulations of data to be done I would suggest using a frontend framework from the likes of Angular or Meteor.

Storing reference data in client onload of browser page in Angularjs

EDIT: I am rephrasing my question again :)
I have an Web Application that uses AngularJS as a client framework. I am currently loading a set of reference data (dependant data sets like Country, State, Region, Codes etc) on every page load. Is there a better way to make the server calls and store the data in a cache. At what point in the Angular life cycle do I make these calls to retrieve and store data?
There are many possible ways to do that. You can make a init call to your api as your page gets loads, and then save the data wherever you want.You can save them using localstorage,sessionstorage, factory, service,constants etc.

Pass a request to a DJANGO REST api using Angular and then return those results in a DJANGO view

Ok, so basically what is happening is I have a search input on my index page. The user types something in the search input, and that is sent to the Django REST api which returns the data in JSON format. I can loop through that results array using Angular ng-repeat. But my question is: is there a way to send that request to another django view and have django return the values using a for loop and a template that I already created?
( I am trying to avoid recreating the template specifically for Angular because that would be repetitive)
Any suggestions, or help on this comes much appreciated. Thank you in advance for taking the time to help me.
All the best.
It depends on the architecture of your application.
If you are building your client as a single page web application using Angular & your business logic is served using the Django REST API in JSON/XML format. Then rendering of the view should be the responsibility of the client side code.
As per me whatever you are doing looks perfectly okay. I don't see any redundancy of the templates in this architecture.

Use list.js in Meteor with data published from the server to the client

I'm currently working on a meteor-Application where I want to use the list.js-JavaScript Library with Meteor.
The use-Case is that I have some data in my MongoDB on the server which I publish to the client. This data should now be rendered in a list and list.js should make it searchable.
The data is published to the client (after a short delay I get the data in the view). But it seems that the list.js-Library is run before the data hits the client. The console says that the array which is searchable only consists of "undefined".
What I've tried now is to use Template.rendered where I put my code of list.js in. But Template.rendered gets fired when the template is rendered, not when the data is receiving the client.
It seems that the data arrives too late to be grabbed by list.js.
Is there something I can do so that list.js will start when the data successfully arrived at the client? Is there something like Data.received?
Thanks in advance!
Unfortunately, that is not the meteor-way to do it. Once you get it working you will see that it lacks performance and proper reactivity.
You should instead look into using meteor's excellent reactivity and do it using template helpers, that way it will be reactive and you can scale it without performance issues.
I found a good answer to your question in the Unofficial Meteor FAQ
That describes how to know when your subscription is ready (reactive data).

Categories

Resources