The code shown for the editor
directive is not creating an isolate scope. Instead, it is creating a new child scope that prototypically inherits from the parent/containing scope.
Since the scroll
directive has scope: false
, it will use the child scope that editor
creates -- no need for $parent
.
Yes, the link function for editor
will run after the link function for scroll
. However, the controller function for editor
(if you define one) will run before the link function for scroll
:
app.directive('scroll', ['$document','$parse', function ($document,$parse) {
return {
restrict: 'E',
replace: true,
transclude: true,
scope:false,
template:
'<div class="scroll">' +
'<div class="content" data-ng-transclude>' +
'</div>' +
'</div>',
link: function (scope, element, attr) {
// some code here....
console.log('link_editor=',scope.link_editor); // value is "undefined"
console.log('ctrl_editor=',scope.ctrl_editor); // value is "true"
}
};
}]);
app.directive('editor', ['$document', function ($document){
return {
restrict: 'EA',
replace: true,
transclude: false,
scope:true,
template:
'<div>' +
'stuff <scroll>content to scroll</scroll> more stuff' +
'</div>',
link: function (scope, element, attrs) {
scope.link_editor = true;
},
controller: function($scope) {
$scope.ctrl_editor = true;
}
};
}]);