typescript import variable from another file

The solution for “typescript import variable from another file” can be found here. The following code will assist you in solving the problem.

//in the first file backendUrls.ts or js
export const rooturl = ‘’;
export const cityListUrl = rooturl + ‘/api/city/’
export const all = {
rooturl, cityListUrl

//in the component
import {Injectable} from ‘@angular/core’;
import {Http} from ‘@angular/http’;
import {backendUrls} from ‘app/backendUrls’; //import the file with variables here

export class cityGetService{
constructor(private http: Http){}

this.http.get(new backendUrls().cityListUrl) //use create new instance to use the variable

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

inline scripts encapsulated in