Skip to content

Instantly share code, notes, and snippets.

@blue193
Created August 15, 2017 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blue193/7d9308452ad8fbb703d0e59fc7917989 to your computer and use it in GitHub Desktop.
Save blue193/7d9308452ad8fbb703d0e59fc7917989 to your computer and use it in GitHub Desktop.
codebase
(function () {
'use strict';
function CbAccountSelector () {
return {
restrict: 'E',
templateUrl: 'views/accounts/cb-account-selector.html',
scope: {
selection: '=?',
load: '=',
source: '=?',
required: '=',
placeholder: '@'
},
controller: function ($scope, Accounts) {
var vm = this;
vm.tempModel = {};
$scope.accounts = $scope.source;
if ($scope.load) {
Accounts.query().$promise
.then(function (accounts) {
$scope.accounts = accounts;
vm.tempModel = _.find($scope.accounts, { id: $scope.selection });
});
}
$scope.$watch('vm.tempModel', function (newValue, oldValue) {
if (!angular.equals(newValue, oldValue) || _.isObject($scope.selection)) {
$scope.selection = !_.isUndefined(newValue) && !_.isUndefined(newValue.id) ? newValue.id : null;
}
});
},
controllerAs: 'vm'
};
}
angular
.module('cashbox')
.directive('cbAccountSelector', CbAccountSelector);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment