Reputation: 93
I'm new in Angular 5. I create services where I set api rootUrl for all my actions like:
@Injectable()
export class UsuariosService {
readonly rootUrl = "http://myapiurl/";
and I use like
list() {
var perfiles = this.http
.get(this.rootUrl + "api/perfiles/listar", this.options)
.map((data: any) => data.json());
return perfiles;
}
I want to know how can I set it globally? In what document should I do it, and how can I import and use it into each service? instead declare it on each one? Regards
Upvotes: 0
Views: 28
Reputation: 167
If you want to have your rootUrl
available in the whole application, the best option would be to put this field in environment.ts
file.
Not only you will able to use it in every file, but you can easily change it for different environments ex. dev
or prod
Here you can find more details: Application Environments
Upvotes: 1