Fix selected account.

This commit is contained in:
Alexis Lahouze 2015-07-15 13:46:08 +02:00
parent c66e164c8d
commit 89b8c7925a

View File

@ -29,8 +29,8 @@ accountantApp
.controller(
"AccountController", [
"$scope", "$rootScope", "$window", "Accounts",
function($scope, $rootScope, $window, Accounts) {
"$scope", "$rootScope", "$window", "$routeParams", "Accounts",
function($scope, $rootScope, $window, $routeParams, Accounts) {
$scope.accountClass = function(account) {
if(account == $scope.selectedAccount) {
@ -174,7 +174,15 @@ accountantApp
// Reset selected account to the new instance corresponding to the old
// one.
if($scope.selectedAccount) {
if($routeParams.accountId) {
// Find the new instance of the previously selected account.
angular.forEach($scope.accounts, function(account) {
if(account.id == $routeParams.accountId) {
// No need to emit accountSelectedEvent.
$scope.selectedAccount = account;
}
});
} else if($scope.selectedAccount) {
// Find the new instance of the previously selected account.
angular.forEach($scope.accounts, function(account) {
if(account.id == $scope.selectedAccount.id) {