0

If i compile and run an angular 2 (or above) application i need to manually go ,to the browser and type localhost path for the output.I need to open the browser automatically whenever i use ng serve command.

1
  • Welcome to StackOverflow! Can you share some code illustrating your problem? Commented Feb 14, 2019 at 12:44

6 Answers 6

1

ng serve --open

or

ng serve -o

This will automatically opens your default browser to http://localhost:4200/.

Sign up to request clarification or add additional context in comments.

Comments

1
ng s -o
 or
ng serve -o

where ng is angular ,s is serve and o is open in the default port(i.e 4200)

serve the angular in the default port

Comments

1

if you are using angular-cli change your package.json as below than type npm start

...
"scripts": {
    "ng": "ng",
    "start": "ng serve --open",
...

Comments

1

Change the package.json

..
"scripts": {
    "ng": "ng",
    "start": "ng serve --open",

Or write the command to your terminal ng serve -o

This will automatically open your default browser.

Comments

1

you can also try with a more flexible config

"scripts": {
  "start": "ng serve && open http://localhost:4200"
}

Comments

0

You will need to write a script to do this. Instructions can be found here How to open browser to localhost through npm scripts

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.