Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

angular declare variable in a file

// global.ts

 export const GlobalVariable = Object.freeze({
     BASE_API_URL: 'http://example.com/',
     //... more of your variables
 });



/*************************** in other files ****************************/


//anotherfile.ts that refers to global constants
import { GlobalVariable } from './path/global';

export class HeroService {
    private baseApiUrl = GlobalVariable.BASE_API_URL;

    //... more code
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #angular #declare #variable #file
ADD COMMENT
Topic
Name
4+3 =