Skip to content

Instantly share code, notes, and snippets.

@richardTowers
Created January 2, 2015 16:12
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 richardTowers/51cd8cfac2d78d003f4d to your computer and use it in GitHub Desktop.
Save richardTowers/51cd8cfac2d78d003f4d to your computer and use it in GitHub Desktop.
function which takes two expressions and binds them together (useful for date processing)
function bindToSeparateDateFieldFactory ($rootScope, $parse) {
return function (context, srcExpression, targetExpression) {
var getTarget = $parse(targetExpression),
setTarget = getTarget.assign,
getSrc = $parse(srcExpression),
setSrc = getSrc.assign;
$rootScope.$watch(
function () { return getTarget(context); },
function (newValue) { newValue && setSrc(context, newValue + 'T00:00:00.000Z'); }
);
$rootScope.$watch(
function () { return getSrc(context); },
function (newValue) { newValue && setTarget(context, newValue.substr(0, 10)); }
);
};
}
@richardTowers
Copy link
Author

this.invoiceIssuedOn = null;

bindToSeparateDateField(this, 'invoice.issuedOn', 'invoiceIssuedOn');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment