Last active
August 8, 2017 17:59
-
-
Save joelstein/f110cb412592582f9d44 to your computer and use it in GitHub Desktop.
Angular Drupal Behaviors directive
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
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(); | |
}); | |
} | |
}; | |
}) | |
; |
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
<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