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.

6 Answers6

1

ng serve --open

or

ng serve -o

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

MonkeyScript
  • 4,776
  • 1
  • 11
  • 28
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

Hameed Syed
  • 3,939
  • 2
  • 21
  • 31
1

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

...
"scripts": {
    "ng": "ng",
    "start": "ng serve --open",
...
Lalji Kanjareeya
  • 135
  • 2
  • 11
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.

Shohel
  • 3,886
  • 4
  • 38
  • 75
1

you can also try with a more flexible config

"scripts": {
  "start": "ng serve && open http://localhost:4200"
}
ABOS
  • 3,723
  • 3
  • 17
  • 23
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

Shane
  • 659
  • 1
  • 9
  • 19