0

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;

2 Answers 2

1

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")
   }
}
Sign up to request clarification or add additional context in comments.

Comments

1

Add to app.module.ts

const APP_CONFIG = new InjectionToken('Application config');
import {environment} from '../environments/environment';

{provide: APP_CONFIG, useValue: environment},

And inside yours component or service

constructor(
    @Inject(APP_CONFIG)
    private readonly _appConfig: Environment
  ) {
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.