Tag Archives: Angular

Angular CLI serve and base href

Several months have passed since Angular 2 was released. Then came Angular CLI promising easier scaffolding and better integration. It’s still in beta and as expected there are things to improve.

One thing that confused me was ng serve and the lack of <base href> support. It’s easy when using ng build with the -bh flag and same feature for serve would’ve been great. Unfortunately the CLI team doesn’t plan on adding base href support 🙁

The project I’m working on relies on multiple other applications and APIs served from other folders. Having base href different than root during development is a must. The only way I found to make the whole setup work was by proxying the needed folder to root.

  • In your index html add the needed <base href>.
    <base href="/project/">
    
  • Create a new file at root called proxy.conf.json and paste:
    [
        {
            "context": [
                "/project"
            ],
            "target": {
                "host": "localhost",
                "protocol": "http:",
                "port": 4200
            },
            "secure": false,
            "pathRewrite": {
                "^/project": "/"
            }
        }
    ]
    
  • Modify your serve command.
    $ ng serve --proxy-config proxy.conf.json /project/ --open true
    

    I set this in package.json start script. After that I can use npm start instead of remembering ng serve and all the parameters.

Applying CSS Styles Before Printing with AngularJS

In a world full of fancy shining jQuery plugins one can’t simply print.

Often you’ll be using a grid JavaScript plugin or another heavy visualization component. One of the pitfalls you might experience with those components is that they don’t look nice when you try to print them. Sometimes this can’t be solved by with the dark side of the force a.k.a pure CSS.

So, what are our options?

Continue reading Applying CSS Styles Before Printing with AngularJS