I have a variable which i want to pass to my directive via scope and then use that variable in link if it is possible. I am fairly new using directives a few things are a bit blurr to me. This is my current code
.directive('imagesFormat', function($cordovaCamera, $ionicModal, $cordovaFile, $cordovaFileTransfer) {
return {
restrict: 'EA',
scope: {
datasource: '&',
},
link: function(scope, element, attrs) {
element.bind("click", function() {
if(attrs.imagesFormat === "takePhoto") {
var options = {
destinationType : Camera.DestinationType.FILE_URI,
sourceType : Camera.PictureSourceType.CAMERA,
allowEdit : false,
encodingType: Camera.EncodingType.JPEG,
popoverOptions: CameraPopoverOptions,
correctOrientation: true
};
}
if(attrs.imagesFormat === "choosePhoto") {
var options = {
destinationType : Camera.DestinationType.FILE_URI,
sourceType : Camera.PictureSourceType.PHOTOLIBRARY,
allowEdit : false,
encodingType: Camera.EncodingType.JPEG,
popoverOptions: CameraPopoverOptions,
mediaType: Camera.MediaType.PICTURE,
correctOrientation: true
};
}
scope.activeSlide = scope.datasource;
});
}
}
})
my html code
<ion-content overflow-scroll='false'>
<div class= "row">
<div class="col">
<button images-format="takePhoto" datasource="$index">Take Photo</button>
</div>
<div class="col">
<button images-format="choosePhoto" datasource="$index">Image Gallery/File</button>
</div>
</div>
</ion-content>
So basically what i want to be able to get in my directive is the value of $index and assign it to scope.activeSlide = scope.datasource thats all