Is there a method for transferring an element from the link function to the controller function within a directive, and then passing it on to another directive as its element?
For example, consider the following directive:
angular.module('myApp').directive('parentDir', function() {
return {
restrict: 'E',
link: function (scope, element, attributes) {
element = //some HTML code
},
controller: function ($scope) {
this.elem = function () {
$scope.elem = element;
}
}
}
});
Now, imagine we have another directive where we want to access the $scope.elem
.
angular.module('myApp').directive('childDir', function() {
return {
restrict: 'E',
link: function (scop, elmn, attr){
// HOW TO GET THE $scope.elem here as elmn ?
elmn = $scope.elem ?
}
}
});
Is it feasible to pass the element
into the $scope.elem
and then to another directive?
Edit: Gratitude to those who provided assistance. I also discovered an alternative approach using a factory
. You can find more information about it here