Search
 
SCRIPT & CODE EXAMPLE
 

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
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: prevent form from reloading with preventDefault 
Javascript :: check if the data can be parsed javascript 
Javascript :: vim react snippets 
Javascript :: check if url contains string 
Javascript :: cypress how to get element length 
Javascript :: how to delete the last part of a string in node js 
Javascript :: remove character at index from string javascript 
Javascript :: json watch command 
Javascript :: jsconfig.json vue 
Javascript :: javascript delete key from object 
Javascript :: How to create $(document).ready() for vanilla JavaScript 
Javascript :: joi enum validation 
Javascript :: canada postal code regex 
Javascript :: url redirect javascript 
Javascript :: redirect function in javascript 
Javascript :: select a random element from from items array 
Javascript :: display toastr warning 
Javascript :: javascript date get minutes with leading zero 
Javascript :: clear canvas 
Javascript :: ajax call too functions.php 
Javascript :: remove all spaces from string javascript 
Javascript :: nodejs express return image 
Javascript :: knockout dump variable 
Javascript :: javascript average function 
Javascript :: javascript compare two objects 
Javascript :: react native open phone 
Javascript :: get value before change and after change js 
Javascript :: get request react 
Javascript :: system collections generic list to javascript array 
Javascript :: javascript for loop starting from end 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =