Skip to content

Instantly share code, notes, and snippets.

@mbenford
Last active September 30, 2020 16:17
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • 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)
}
});
@Josh68
Copy link

Josh68 commented May 1, 2015

Very useful in my project, in combination with a custom directive where I need to set the name on an input within the template and have it validate angular-style. Thanks.

@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