-
-
Save KennyLisc/7819189 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//html | |
// <div ng-controller="FileUploadCtrl"> | |
// <p class="lead">CSV and *.pl is feasible.</p> | |
// <form action="/upload" file-upload> | |
// <a id="btnUploadCSV" class="btn btn-success" ng-click="triggerUpload()">Upload CSV</a> | |
// <a id="btnUploadPL" class="btn btn-info" ng-click="triggerUpload()">Upload *.pl</a> | |
// <!--btn will trigger the input field to upload--> | |
// <input type="file" id="inputUpload" name="inputupload" style="visibility: hidden;" /> | |
// <button type="submit" class="btn" >submit</button> | |
// </form> | |
// </div> | |
// file upload controller | |
function FileUploadCtrl($scope) { | |
//when upload finished | |
$scope.uploadFinished=function(e,data){ | |
console.log(e) | |
console.log(data) | |
}; | |
//trigger the input to upload | |
$scope.triggerUpload = function () { | |
jQuery('#inputUpload').click(); | |
}; | |
} | |
getRNIAapp.directive('fileUpload', function() { | |
return { | |
restrict : 'A', | |
controller : 'FileUploadCtrl', | |
link : function(scope, element, attrs, ctrl) { | |
var options = { | |
url:'/upload', | |
target:'#response', | |
type:'POST', | |
beforeSubmit : function() { | |
// callback: upload started | |
console.log('before submit...') | |
}, | |
success : function() { | |
// callback: upload complete | |
console.log('success...') | |
} | |
}; | |
// element - this is jquery element | |
element.ajaxForm(options); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment