Created
January 2, 2015 16:12
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); } | |
); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this.invoiceIssuedOn = null;
bindToSeparateDateField(this, 'invoice.issuedOn', 'invoiceIssuedOn');