我有一個變量,我想通過範圍傳遞給我的指令,然後在鏈接中使用該變量(如果可能的話)。我是相當新的使用指令,有些事情對我來說有點模糊。這是我當前的代碼通過範圍將變量傳遞給指令angularjs
.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;
});
}
}
})
我的HTML代碼
<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>
所以基本上我希望能夠在我的指令,得到的是$index
值並將其分配給scope.activeSlide = scope.datasource
多數民衆贊成
數據源: '&',和用於功能varible use「=」 – PavanAsTechie
$ index從哪裏來?它是一個自定義函數,變量或字符串,你在你的範圍設置?還是來自一個角度指令,如ng-repeat? –