diff --git a/src/operations/balance-chart.component.js b/src/operations/balance-chart.component.js index 422b7c3..f6dd4cd 100644 --- a/src/operations/balance-chart.component.js +++ b/src/operations/balance-chart.component.js @@ -35,6 +35,7 @@ var balanceChartModule = angular.module('balanceChartModule', [ .component('balanceChart', { template: '
', bindings: { + account: '<', onUpdate: '&' }, controller: function($routeParams, Balances, Account, $element) { @@ -131,10 +132,6 @@ var balanceChartModule = angular.module('balanceChartModule', [ }, y: { show: true, - lines: [ - { value: 0, axis: 'y2' }, - { value: 0, axis: 'y', class: 'zeroline'} - ] } }, tooltip: { @@ -153,12 +150,34 @@ var balanceChartModule = angular.module('balanceChartModule', [ }); vm.loadData(); + }; + + vm.setLines = function(account) { + if(vm.chart) { + vm.chart.ygrids([ + { value: 0, axis: 'y2' }, + { value: 0, axis: 'y', class: 'zeroline'}, + ]); - Account.get({id: $routeParams.accountId}, function(result) { vm.chart.ygrids.add({ - value: result.authorized_overdraft, class: 'overdraft' + value: account.authorized_overdraft, + axis: 'y', + class: 'overdraft' }); - }); + } + }; + + vm.$onChanges = function(changes) { + if('account' in changes) { + if('$promise' in vm.account && vm.account.$resolved === false) { + vm.account.$promise.then(function(account) { + vm.setLines(account); + return account; + }); + } else { + vm.setLines(vm.account); + } + } }; } }).factory('Balances', function($resource) {