Use DOCUMENT from angular/common, Ref: #347

This commit is contained in:
ziajka 2019-03-22 13:43:53 +01:00
parent 038f3682eb
commit ddf2db7df6
2 changed files with 14 additions and 5 deletions

View File

@ -6,7 +6,8 @@ import { ServerService } from '../../services/server.service';
import { MockedServerService } from '../../services/server.service.spec';
import { Server } from '../../models/server';
describe('LocalServerComponent', () => {
fdescribe('LocalServerComponent', () => {
let component: LocalServerComponent;
let fixture: ComponentFixture<LocalServerComponent>;
let router: any;
@ -24,7 +25,8 @@ describe('LocalServerComponent', () => {
spyOn(serverService, 'getLocalServer').and.returnValue(Promise.resolve(server));
TestBed.configureTestingModule({
providers: [{ provide: Router, useValue: router }, { provide: ServerService, useValue: serverService }],
providers: [{ provide: Router, useValue: router },
{ provide: ServerService, useValue: serverService }],
declarations: [LocalServerComponent]
}).compileComponents();

View File

@ -1,8 +1,9 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, Inject } from '@angular/core';
import { Router } from '@angular/router';
import { ServerService } from '../../services/server.service';
import { Server } from '../../models/server';
import { DOCUMENT } from '@angular/common';
@Component({
selector: 'app-local-server',
@ -10,10 +11,16 @@ import { Server } from '../../models/server';
styleUrls: ['./local-server.component.scss']
})
export class LocalServerComponent implements OnInit {
constructor(private router: Router, private serverService: ServerService) {}
constructor(
private router: Router,
private serverService: ServerService,
@Inject(DOCUMENT) private document) {}
ngOnInit() {
this.serverService.getLocalServer(location.hostname, parseInt(location.port, 10)).then((server: Server) => {
this.serverService.getLocalServer(
this.document.location.hostname,
parseInt(this.document.location.port, 10))
.then((server: Server) => {
this.router.navigate(['/server', server.id, 'projects']);
});
}