Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. angular.module('compile', [], function($compileProvider) {
  2. // configure new 'compile' directive by passing a directive
  3. // factory function. The factory function injects the '$compile'
  4. $compileProvider.directive('compile', function($compile) {
  5. // directive factory creates a link function
  6. return function(scope, element, attrs) {
  7. scope.$watch(
  8. function(scope) {
  9. // watch the 'compile' expression for changes
  10. return scope.$eval(attrs.compile);
  11. },
  12. function(value) {
  13. // when the 'compile' expression changes
  14. // assign it into the current DOM
  15. element.html(value);
  16.  
  17. // compile the new DOM and link it to the current
  18. // scope.
  19. // NOTE: we only compile .childNodes so that
  20. // we don't get into infinite loop compiling ourselves
  21. $compile(element.contents())(scope);
  22. }
  23. );
  24. };
  25. })
  26. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement