是否将链接函数中的元素传递给控制器函数内部指令并将其传递给另一个指令作为其元素?从链接功能到控制器功能从内部指令到另一个指令传递元素
我的意思是我有一个指令:
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;
}
}
}
});
然后我还有一个指令,我想要得到的$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 ?
}
}
});
是否有可能在element
传递到$scope.elem
而且比另一个指令?
编辑:谢谢你们的帮助,我还发现了另一种方式来做到这一点通过factory
under this link
感谢'$ element'。不知道它存在。 – Akash