0

Lets say I have a typescript file environment.ts where I export

export const environment = {
    host: localhost:8080,

    // more keys/values
}

Lets say I have another file url.ts where I want to import the environment object.

import { environment } from 'environments/environment';

Which works fine. I could do there something like

const host = environment.host

Question:

But, is there any way to just import the host value directly?

1
  • are you working with cli? and exactly, what do you mean with "import directly"? Commented Feb 19, 2018 at 11:11

2 Answers 2

2

Instead of exporting a toplevel object named environment you could export each value separately

export const host = 'localhost:8080';
export const foo = 'bar';

and then import them like this

import { host, foo } from 'environments/environment'

or import them all like this

import * as environment from 'environments/environment'
Sign up to request clarification or add additional context in comments.

Comments

0

if you are working with angular cli, you could modify your .angular-cli.json file like this:

{
  "defaults": {
    "serve": {
      "port": 8080,
      "host": "yourHost"
    }
  }
}

1 Comment

I was asking for typescript in general.

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.