I have a page with 2 containers on it , each one contains images. I want to add some specific visual attributes and functionalities to these images. These specific stuff is similar in both depositories but it is not the same. So i want to create one directive for 2 types of images , but i want it to behaviour a little bit differently depending on in what depository ( actually, scope ) image is placed. Checking for element's scope in directive's body:
studio.directive('orientable', function () {
return {
link: function(scope, element, attrs) {
if(scope.id=="Depository1"){
// give to element some specific behaviour
}else if(scope.id=="Depository2"){
// give to element another specific behaviour
}
}
}
seems ugly to me.
I can't use passing arguments to a directive, because then image's tag will turn to unreadable and when there are many images it will be disaster . I do not want two directives because they will be basically same.
So i want one directive , but somehow it must be "polymorphic".
Is it some kind of inheritance possible here? I think i'm missing something important in understanding of Angular' directives .
scope:true. otherwise, twoorientablewill be sharing things