diff --git a/src/app.config.ts b/src/app.config.ts index 7fe96a5..d9d521e 100644 --- a/src/app.config.ts +++ b/src/app.config.ts @@ -2,7 +2,6 @@ import { Level } from '@nsalaun/ng-logger'; var operationsTmpl = require('./operations/operations.html'); -var schedulerTmpl = require('./scheduler/scheduler.html'); export default function AppConfig($uiRouterProvider) { $uiRouterProvider.trace.enable(1); @@ -21,9 +20,12 @@ export default function AppConfig($uiRouterProvider) { $stateRegistry.register({ name: 'scheduler', url: '/account/:accountId/scheduler', - templateUrl: schedulerTmpl, - controller: 'SchedulerController', - controllerAs: 'schedulerCtrl' + component: 'scheduleComponent', + resolve: { + accountId: function($transition$) { + return $transition$.params().accountId; + } + } }); $stateRegistry.register({ diff --git a/src/scheduler/index.ts b/src/scheduler/index.ts index 0937603..d22c23a 100644 --- a/src/scheduler/index.ts +++ b/src/scheduler/index.ts @@ -33,6 +33,8 @@ var ngMessages = require('angular-messages'), ngUiNotification = require('angular-ui-notification'), ngStrap = require('angular-strap'); +var schedulerTmpl = require('./scheduler.html'); + import { ScheduleController } from './schedule.controller'; import { ScheduleService } from './schedule.service'; @@ -49,6 +51,13 @@ export default angular.module('accountant.scheduler', [ .factory('scheduleService', downgradeInjectable(ScheduleService)) - .controller('SchedulerController', ScheduleController) + .component('scheduleComponent', { + bindings: { + accountId: '<' + }, + templateUrl: schedulerTmpl, + controller: ScheduleController, + controllerAs: 'schedulerCtrl' + }) .name; diff --git a/src/scheduler/schedule.controller.ts b/src/scheduler/schedule.controller.ts index ffdafd2..9e83e5a 100644 --- a/src/scheduler/schedule.controller.ts +++ b/src/scheduler/schedule.controller.ts @@ -11,15 +11,17 @@ var scheduleFormTmpl = require('./schedule.form.tmpl.html'), scheduleDeleteTmpl = require('./schedule.delete.tmpl.html'); export class ScheduleController{ + accountId: number; operations = []; constructor( - private $stateParams, private toastrService: ToastrService, private scheduleService: ScheduleService, private logger: Logger, private $modal - ) { + ) {} + + $onInit = function() { // Load operations on controller initialization. this.load(); } @@ -29,7 +31,7 @@ export class ScheduleController{ */ add = function() { var schedule = new Schedule(); - schedule.account_id = this.$stateParams.accountId; + schedule.account_id = this.accountId; return this.modify(schedule); }; @@ -38,9 +40,11 @@ export class ScheduleController{ * Load operations. */ load = function() { - return this.scheduleService.query(this.$stateParams.accountId) + return this.scheduleService.query(this.accountId) .subscribe((schedules: Schedule[]) => { this.operations = schedules; + }, (reason) => { + this.logger.log("Got error", reason); } ); };