How to sync database and angular component? - javascript

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.

Related

How to implement a weather API in cordova

I have to create an android weather app with cordova using data from openweathermap.
The thing is I install cordova and I get to the "hello world", but I have no idea how to get data from openweather.
I create the project in cordova, then I can edit that hello world as it was a web page using html, and css.
But how do I make it to search for places and get data from openweathermap?
I have registered in openweathermap, got my own key, but don't know how to use it.
Don't even know what sohld I study to learn how to do it.
I think I should make a request to the openweather API, then openweather will reply with the weather data in json format, then I should get that data to my website/cordova app.
But how?
Thank you
Been looking for tutorials, but none I found explain what I want.
They use Ionic or react, stuff I don't know how to use.
I would like to keep it simple, just look for the city, and get the weather displayed, to know how it is done.
TL;DR - You are going to be making GET requests to the server
Ok so, what you're looking for is the ability to fetch the weather data from the API server and display it on your component template somehow. What you need is the HTTPClientModule that comes with angular (and therefore with Ionic if you are using Angular as your frontend framework, v4 works with Vue and React as well).
I know this is rough for a lot of new developers so I'll make it as simple as possible for you, import the HTTPClientModule inside your app module so you can use it globally. Then, the best practice is to place all API calls(which is how you'll fetch the weather data with your key) inside a service. Create a GET request to the URI endpoint associated with the data you require and voila, you have your data.
From there, go to your page's typescript file and import the service and declare it in the class constructor. From there, you can make a function that subscribes (since Angular ships with RxJS) to the service function that fetches your data and saves it to a variable.
If you want to pass that onto your component view, well I'm sure you have interpolation figured out. Don't forget to use the async pipe since you are fetching asynchronous data.

Api call request limit of 1 call each hour

I use an API in Switzerland, which allows me to request the api one time every hour in production.
I don't need more than one request each week, since it's event data, but I don't know what i have to do that i can use this api for 200+ users each day.
Do I have to save the data somewhere like firebase or are there services for this? I'm very new in this field. Could you give me a hint?
Building on top of what Dr. cool said, you'll most likely want to use cron jobs: http://code.tutsplus.com/tutorials/scheduling-tasks-with-cron-jobs--net-8800
Also keep in mind, some API's do not allow you to store the data they provide on your own server. Make sure you read the terms of use before doing so from the API provider.
It's better to have a program on the server that can run once a week and load data from the API. This data should be saved in a database. Then when one of your users needs the data, it's ready to load from your database without hitting the API limit.
Yes, Firebase is a great option. Or you can use MySQL or other server-side databases.

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.

Problems using $interval to create a live feed?

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?

Saving data from 3rd party API to CouchDB using AngularJS

I have a working frontend app build with AngularJS.
It interacts with a couple of 3rd party APIs and is getting data without a problem.
The next step of the app would be to store this data into a CouchDB everytime a search is made. I want to build my own db little by little and to eventually rely on it and not on the 3rd party API (e.g., the app first makes a query to my database, if it doesnt find what's needed, takes it from the 3rd party API, displays it on the frontend but it also saves it on my database, so next time the same search is conducted, the results will come from my resource).
Do I need to use nodejs and some module (express, nano, etc) or can I rely only on AngularJS to write data to the DB?
CouchDB has a simple REST interface that you can call directly from AngularJS. There's a Angular module for it as well called CornerCouch

Categories

Resources