I am new in Angular2. I would like to have a single class or a configuration file having all my API endpoints (allowing parameters and such in the different routes) that I could inject in all my services. What's the best way to do so in Angular2. I mean, should I define an @Injectable class as you would do when defining a service (and then add it to my services'PROVIDERS).
The problem that I found is when I will deploy my api on a server in the client part I must change all endpoint called in string format so it will be wasted time if I have many endpoints to work with.
in this example I call a service with an endpoint in string format :
getData() {
return this._http.get('http://localhost:8000/cartography')
.map(function(res) {
const jsonArray = res.json();
const newJsonArr = [];
for ( let i = 0; i < jsonArray.length; i++) {
const object = {
post_name : jsonArray[i].name,
employment_name : jsonArray[i].employment.name,
profession_name : jsonArray[i].employment.profession.name,
family_name : jsonArray[i].employment.profession.family.name
};
newJsonArr.push(object);
}
return newJsonArr;
});
}
so I'm looking for a way to define it as global var in a class or config file. any help please ! thanks .