Skip to content

Instantly share code, notes, and snippets.

@mbenford
Last active September 30, 2020 16:17
Show Gist options
  • Save mbenford/dd7556f01963f49e5c7d to your computer and use it in GitHub Desktop.
Save mbenford/dd7556f01963f49e5c7d to your computer and use it in GitHub Desktop.
Angular directive that binds attributes without relying on interpolation
<input type="text" ng-bind-attrs="{placeholder: somePropertyOfTheScope, tabindex: anotherPropertyOfTheScope}" >
app.directive('ngBindAttrs', function() {
return function(scope, element, attrs) {
scope.$watch(attrs.ngBindAttrs, function(value) {
angular.forEach(value, function(value, key) {
attrs.$set(key, value);
})
}, true)
}
});
@annaswigart
Copy link

This is very helpful, thanks for sharing!

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