Skip to content

Instantly share code, notes, and snippets.

@joelstein
Last active August 8, 2017 17:59
Show Gist options
  • Save joelstein/f110cb412592582f9d44 to your computer and use it in GitHub Desktop.
Save joelstein/f110cb412592582f9d44 to your computer and use it in GitHub Desktop.
Angular Drupal Behaviors directive
angular.module('drupalBehaviors', [])
.directive('drupalBehaviors', function($timeout) {
return {
restrict: 'AE',
link: function(scope, element, attrs) {
function attach() {
$timeout(function() {
Drupal.attachBehaviors(element.get(0), drupalSettings);
});
}
scope.$watch(attrs.drupalBehaviors, function(value) {
attach();
});
}
};
})
;
<div ng-repeat="thing in things" drupal-behaviors="scopeVariableToWatchForChanges">
<!-- Stuff in here will get manipulated by Drupal behaviors when added to DOM -->
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment