Add accountIdService to be able to correctly retrieve accountId in UiRouter transition.

This commit is contained in:
Alexis Lahouze 2017-07-25 08:53:08 +02:00
parent ad16b5a391
commit fa9402e25e

View File

@ -30,6 +30,7 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
var ngStrap = require('angular-strap'); var ngStrap = require('angular-strap');
import uiRouter from '@uirouter/angularjs';
var schedulerTmpl = require('./scheduler.html'); var schedulerTmpl = require('./scheduler.html');
@ -37,6 +38,7 @@ import { ScheduleComponent } from './schedule.component';
import { ScheduleService } from './schedule.service'; import { ScheduleService } from './schedule.service';
export default angular.module('accountant.scheduler', [ export default angular.module('accountant.scheduler', [
uiRouter,
ngStrap ngStrap
]) ])
.factory('toastrService', downgradeInjectable(ToastrService)) .factory('toastrService', downgradeInjectable(ToastrService))
@ -45,6 +47,19 @@ export default angular.module('accountant.scheduler', [
.factory('logger', downgradeInjectable(Logger)) .factory('logger', downgradeInjectable(Logger))
.factory('accountIdService', function() {
var accountId: null;
return {
get: () => {
return accountId;
},
set: (value) => {
accountId = value;
}
}
})
.factory('scheduleService', downgradeInjectable(ScheduleService)) .factory('scheduleService', downgradeInjectable(ScheduleService))
.component('scheduleComponent', { .component('scheduleComponent', {
@ -57,4 +72,10 @@ export default angular.module('accountant.scheduler', [
controllerAs: 'schedulerCtrl' controllerAs: 'schedulerCtrl'
}) })
.run(function($transitions, accountIdService) {
$transitions.onSuccess({}, (transition) => {
accountIdService.set(transition.params().accountId);
});
})
.name; .name;