I have a directive for uploading files. I am calling this in my view called "UploadRecords.html". I have a button called "Upload" in "UploadRecords.html". On click of this button, I want to call the "UploadAll" method defined inside the link function in my directive. What are the ways to achieve this.
Basically I want to call a directive function on click of a root scope element.
Note: I am using isolated scope in my directive
angular.module('fileUpload', [])
.directive(
"fileUpload",
function () {
return ({
restrict: 'E',
scope: {
onSuccess: '&',
onError: '&',
},
templateUrl: 'Templates/FileUploadTemplate.html',
link: function (scope, element, attrs) {
scope.files = [];
scope.addFile = function (element, documentType) {
if (element.files.length > 0) {
$.each(element.files, function (index, file) {
scope.files.push(file);
});
}
scope.$apply();
}
scope.uploadAll = function () {
//This is where I upload the files to the web api using a FormData post
}
}
});
}
);
<file-upload on-success="onFileUloadAllSuccess()" on-error="onFileUloadAllError()"></file-upload>
<button type="button" class="btn btn-default">Upload All</button>
Thanks, Sam.