我有一个指令
<child-div child-data="childData"></child-div>
我要求我必须根据以下情况关联点击操作
问题是当条件2满足时,我无法获得childDiv指令的父元素。
任何人都可以告诉我我该怎么做。 在此先感谢
'use strict';
angular.module('testDirectives')
.directive('childDiv', function ( $compile, $q){
return {
restrict: 'EAC',
scope: {
actionInstance: '=',
},
replace : true,
templateUrl : 'template.html',
link: function (scope, element, attrs) {
status = isViewAssociatedWithAction();
if(status){ //action on directive
element.css('cursor', 'pointer');
element.bind('click', function(){
actionCode = scope.actionInstance.actionCode;
//do something
})
}
else{//action on parent element of directive need to apply
element.parent().on('click', function () {
console.log('Parent div has action');
})
}
function isViewAssociatedWithAction(){
return (scope.actionInstance.showActionLabel || scope.actionInstance.showActionIcon) ? true : false;
}
}
}
});