2017-02-09 26 views
2

我已經設置了angular-cli.json第9行「outDir」:「dist/bice /」,並且構建很好,但我需要開發環境來反映bice子目錄。例如。 http://localhost:4200/bice/如何通過子目錄服務Angular 2 CLI ng

統計:

的Linux(弓/ 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 

回答

1

所以我通過導入環境,並檢查是否生產或沒有解決這個問題。

接下來是如何使它在應用程序中更高,這樣我就可以在任何地方設置它並讓它反映在所有組件上。我在考慮app.component級別。

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() { 

} 
} 
+0

如果這解決了您的問題,請將其標記爲接受的答案。 :) – msanford