Skip to content

Instantly share code, notes, and snippets.

@sebble
Last active October 8, 2016 15:35
Show Gist options
  • Save sebble/4ee72219a1b67677c7eef9e9f7422326 to your computer and use it in GitHub Desktop.
Save sebble/4ee72219a1b67677c7eef9e9f7422326 to your computer and use it in GitHub Desktop.
import { Component } from '@angular/core';
import { NginxlogService } from './nginxlog.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app works!';
constructor(private nginxlogService: NginxlogService) { }
}
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './routing.module';
import { OneComponent } from './one/one.component';
import { TwoComponent } from './two/two.component';
import { NginxlogService } from './nginxlog.service';
@NgModule({
declarations: [
AppComponent,
OneComponent,
TwoComponent,
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
AppRoutingModule,
],
providers: [NginxlogService],
bootstrap: [AppComponent]
})
export class AppModule { }
import { Injectable } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';
@Injectable()
export class NginxlogService {
constructor(private router: Router) {
router.events.subscribe(e => {
if (e instanceof NavigationEnd) {
//console.log(e['urlAfterRedirects']);
let request = new XMLHttpRequest();
request.open('OPTIONS', e['urlAfterRedirects'], true);
request.send();
}
});
}
}
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { OneComponent } from './one/one.component';
import { TwoComponent } from './two/two.component';
@NgModule({
imports: [
RouterModule.forRoot([
{ path: '', redirectTo: '/one', pathMatch: 'full' },
{ path: 'one', component: OneComponent },
{ path: 'two', component: TwoComponent }
])
],
exports: [
RouterModule
]
})
export class AppRoutingModule {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment