Created
August 5, 2014 17:46
-
-
Save SimplGy/4197b03424bd7766cc62 to your computer and use it in GitHub Desktop.
Compile order of parent and child directives in AngularJS
This file contains 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
/* | |
1. compile methods of all directives, run in order | |
2. controller | |
3. pre-link | |
4. (all actions of children directives) | |
5. post-link (AKA regular `link` function) | |
*/ | |
var app = angular.module('app',[]); | |
app.directive('bigPoppa', function($q){ | |
return { | |
restrict: 'E', | |
controller: function($scope){ console.log('bigPoppa controller'); }, | |
compile: function(scope, el) { | |
console.log('bigPoppa compile'); | |
return { | |
pre: function(){ console.log('bigPoppa pre'); }, | |
post: function(){ console.log('bigPoppa post'); } | |
}; | |
} | |
} | |
}); | |
app.directive('babyBird', function(){ | |
return { | |
restrict: 'E', | |
controller: function(){ console.log('babyBird controller'); }, | |
compile: function(scope, el) { | |
console.log('babyBird compile'); | |
return { | |
pre: function(){ console.log('babyBird pre'); }, | |
post: function(){ console.log('babyBird post'); } | |
}; | |
} | |
} | |
}); | |
console.log(''); // blank line |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The output is: