Search code examples
angularangular7

Angular - How to write HTML logic based on Environments


In Angular application, I have to display different tables in html based on Production, QA or Test environments.

I have imported below but not sure how to determine QA or Prod environment. Can someone please help me to handle this

import { environment } from ../../../environments/environment;

Expected Behavior:

if( environment = 'Production') 
 displaycolumns = 5;
else if( environment = 'QA')
 displaycolumns = 3;
else
 displaycolumns = 2;

Solution

  • Use this in the component/service where you need you check the environemt

    import { environment } from '../../environments/environment';
    
    someFunction(){
       if(environment.production){
          console.log("In Production")
       }
       else{
          console.log("In devlopment")
       }
    }