Last active
September 30, 2020 16:17
-
-
Save mbenford/dd7556f01963f49e5c7d to your computer and use it in GitHub Desktop.
Angular directive that binds attributes without relying on interpolation
This file contains hidden or 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
<input type="text" ng-bind-attrs="{placeholder: somePropertyOfTheScope, tabindex: anotherPropertyOfTheScope}" > |
This file contains hidden or 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
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) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is very helpful, thanks for sharing!