angular.module('location').controller('locationFieldController', ['$scope', '$window', function locationFieldController($scope, $window) { $scope.data = { id: 0, password: '' } $scope.$watch('data', function(newValue) { $scope.model = JSON.stringify(newValue); }, true); $scope.selectLocation = function selectLocation($event, id) { if (angular.element($event.target).hasClass('bwlp-password-input')) return; $scope.data.password = ''; if ($scope.data.id === id) { $scope.data.id = 0; angular.element('.selected-location').removeClass('selected-location'); return; } $scope.data.id = id; angular.element('.selected-location').removeClass('selected-location'); angular.element($event.currentTarget).addClass('selected-location'); }; }]);