📌 Set environment variable

This commit is contained in:
corner 2019-09-09 17:31:34 +02:00
parent 75b6a0f45d
commit 7f4eb556d5
5 changed files with 22 additions and 6 deletions

View File

@ -1 +1,3 @@
<h1>App works!</h1> <app-nav></app-nav>
<router-outlet></router-outlet>
<app-controls></app-controls>

View File

@ -1,7 +1,10 @@
// Imports
import { BrowserModule } from '@angular/platform-browser'; import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module'; import { AppRoutingModule } from './app-routing.module';
import { HttpClientModule } from '@angular/common/http';
// Components
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import { HomeComponent } from './components/home/home.component'; import { HomeComponent } from './components/home/home.component';
import { ControlsComponent } from './components/controls/controls.component'; import { ControlsComponent } from './components/controls/controls.component';
@ -16,7 +19,8 @@ import { NavComponent } from './components/nav/nav.component';
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
AppRoutingModule AppRoutingModule,
HttpClientModule
], ],
providers: [], providers: [],
bootstrap: [AppComponent] bootstrap: [AppComponent]

View File

@ -1,4 +1,5 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { DataService } from 'src/app/services/data.service';
@Component({ @Component({
selector: 'app-home', selector: 'app-home',
@ -7,9 +8,10 @@ import { Component, OnInit } from '@angular/core';
}) })
export class HomeComponent implements OnInit { export class HomeComponent implements OnInit {
constructor() { } constructor(private data: DataService) { }
ngOnInit() { ngOnInit() {
this.data.testConnection();
} }
} }

View File

@ -1,9 +1,15 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from 'src/environments/environment.prod';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class DataService { export class DataService {
constructor() { } constructor(private http: HttpClient) { }
testConnection() {
this.http.get(`${environment.apiUrl}/query.php`).subscribe(() => {}, (err) => { throw new Error(err); });
}
} }

View File

@ -1,3 +1,5 @@
export const environment = { export const environment = {
production: true production: true,
// The apiUrl should point to the api folder of the server-side code. E.g. https://jobbel.nl/music (No ending slash)
apiUrl: ''
}; };