1//in the first file backendUrls.ts or js
2export const rooturl = 'http://127.0.0.1:8000';
3export const cityListUrl = rooturl + '/api/city/'
4export const all = {
5 rooturl, cityListUrl
6}
7
8//in the component
9import {Injectable} from '@angular/core';
10import {Http} from '@angular/http';
11import {backendUrls} from 'app/backendUrls'; //import the file with variables here
12
13@Injectable()
14export class cityGetService{
15 constructor(private http: Http){}
16
17 cityGet(){
18 this.http.get(new backendUrls().cityListUrl) //use create new instance to use the variable
19 }
20}
21