I am completely new to AngularJS and feeling overwhelmed.
So I created this file to fetch data from an API with a time filter.
forecast.js
(function() {
angular.module('application').factory('Forecast', ['$http', '$q', function($http, $q){
var ApiAddr = "api.com/";
forecast.getResults = function(timeStart, timeEnd){
// Mapping application variable names with API parameter names
var httpParams = {
type: "global",
time: "minute",
tsmin: timeStart,
tsmax: timeEnd
};
return $http.get(apiAddr, {
params: httpParams,
cache: true
}).then(function(data){
return data;
},
function(response){
console.log(
"HTTP request "+ApiAddr+
" (with parameters tsmin="+httpParams.tsmin+", tsmax="+httpParams.tsmax+
", type="+httpParams.type+", time="+httpParams.time+
(httpParams.motive ? ", motive="+httpParams.motive : "")+
(httpParams.vector ? ", vector="+httpParams.vector : "")+
(httpParams.media ? ", media="+httpParams.media : "")+
") failed with "+response.status
);
return $q.reject(response);
}
);
}];
But I have no clue how to create a controller adapter for this. What type of controller should I use? All the examples I've found are based on fixed JSON files with no parameters.
Additionally, I want to input the time filter in HTML, but I have no idea where to start. The examples I've seen only show how to retrieve data, not send it.
Ps: I have spent 2 days researching this, as I have never worked with front-end programming before.