Upgrade routing to Angular2.

This commit is contained in:
Alexis Lahouze
2017-08-01 23:09:21 +02:00
parent 2ae8a9cfad
commit 5726d8bf2e
13 changed files with 81 additions and 59 deletions

View File

@ -4,6 +4,7 @@ import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { RouterModule } from '@angular/router';
import { NgLoggerModule, Level } from '@nsalaun/ng-logger';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
@ -16,16 +17,16 @@ import { ScheduleEditModalComponent } from './scheduleEditModal.component';
import { ScheduleFormComponent } from './scheduleForm.component';
import { ScheduleRowComponent } from './scheduleRow.component';
import { ScheduleListComponent } from './scheduleList.component';
export function accountIdServiceFactory(i: any) {
return i.get('accountIdService');
}
import { ScheduleListState } from './schedule.states';
@NgModule({
imports: [
HttpClientModule,
CommonModule,
FormsModule,
RouterModule.forChild([
ScheduleListState
]),
NgLoggerModule,
ToastrModule,
NgbModule,
@ -33,11 +34,6 @@ export function accountIdServiceFactory(i: any) {
],
providers: [
ScheduleService,
{
provide: 'accountIdService',
deps: ['$injector'],
useFactory: accountIdServiceFactory
}
],
declarations: [
ScheduleDeleteModalComponent,

View File

@ -1,7 +1,8 @@
// vim: set tw=80 ts=2 sw=2 sts=2 :
import { ScheduleListComponent } from './scheduleList.component';
export const ScheduleListState = {
name: 'scheduler',
url: '/account/:accountId/scheduler',
component: 'scheduleListComponent',
path: 'account/:accountId/scheduler',
component: ScheduleListComponent,
}

View File

@ -1,4 +1,6 @@
import { Component, Inject, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs/Rx';
import { Logger } from '@nsalaun/ng-logger';
@ -53,7 +55,7 @@ export class ScheduleListComponent implements OnInit {
private scheduleService: ScheduleService,
private logger: Logger,
private ngbModal: NgbModal,
@Inject('accountIdService') private accountIdService
private route: ActivatedRoute,
) {}
$onInit() {
@ -62,7 +64,7 @@ export class ScheduleListComponent implements OnInit {
ngOnInit() {
this.logger.log("ngOnInit");
this.accountId = this.accountIdService.get();
this.accountId = +this.route.snapshot.paramMap.get('accountId')
// Load operations on controller initialization.
this.load();
}