Lance
Lance

Reputation: 61

How To have Angular 2 CLI ng serve via subdirectory

I have set angular-cli.json line 9 "outDir": "dist/bice/" and the build is fine but I need the development environment to reflect the bice sub directory. E.g. http://localhost:4200/bice/

Stats:

Linux (arch/antergos)

angular-cli: 1.0.0-beta.24
node: 7.5.0
os: linux x64
@angular/common: 2.4.0
@angular/compiler: 2.4.0
@angular/core: 2.4.0
@angular/forms: 2.4.0
@angular/http: 2.4.0
@angular/platform-browser: 2.4.0
@angular/platform-browser-dynamic: 2.4.0
@angular/router: 3.4.0
@angular/compiler-cli: 2.4.0

Upvotes: 2

Views: 734

Answers (1)

Lance
Lance

Reputation: 61

So I solved this issue by importing the environments and checking if production or not.

Next is how to bring it higher in the app so I can set this anywhere and have it reflect on all components. I am thinking at the app.component level.

import { Component, OnInit } from '@angular/core';
import { environment } from '../../environments/environment';

if (environment.production) {
var urlProduction = null;
urlProdcution = '/bice';
}

@Component({
selector: 'app-presentation',
templateUrl: './presentation.component.html',
styleUrls: ['./presentation.component.sass']
})
export class PresentationComponent implements OnInit {
moduleTitle1 = 'Presentation Module';
moduleDescription1 = 'This will be the short description of the module and what sort of training it provides. From here the user can click the button and the pop-up modal will show up. An idea is to place a check mark on ones that users have completed...';
moduleButton1 = 'START MODULE';
url = urlProduction; // {{url}} in the template.

constructor() { }

ngOnInit() {

}
}

Upvotes: 1

Related Questions