Created
February 2, 2015 16:59
-
-
Save malko/2bdee97a8101ea4900d0 to your computer and use it in GitHub Desktop.
parseBindingAttr for angular
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
/** By J.louis */ | |
function parseExprAttr($parse, $scope, $attrs, name) { | |
var fn = $parse($attrs[name]), | |
res | |
; | |
res = function (locals) { | |
return fn($scope, locals); | |
}; | |
res.assign = fn.assign && function (value) { | |
fn.assign($scope, value); | |
}; | |
return res; | |
} | |
function parseBindingAttr($parse, $scope, $attrs, name, optional) { | |
var res; | |
if (!(name in $attrs)) { | |
if (!optional) { | |
throw new Error(name + ' attribute must be specified'); | |
} | |
let value; | |
res = function () { | |
return value; | |
}; | |
res.assign = function (v) { | |
value = v; | |
}; | |
return res; | |
} | |
res = parseExprAttr($parse, $scope, $attrs, name); | |
if (!res.assign) { | |
throw new Error(name + ' model must be assignable'); | |
} | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment