i want upload file on server , have progress bar. use ajax upload. now, want convert them angularjs. how use ajax on angularjs. i'm researching ngularjs. please, me.thanks html:
<form action="uploadfile" method="post" enctype="multipart/form-data"> <input type="file" name="file" multiple><br> <input type="submit" value="upload file server"> </form> <div class="progress"> <div class="bar"></div > <div class="percent">0%</div > </div> <div id="status"></div> and js file :
<script> (function() { var bar = $('.bar'); var percent = $('.percent'); var status = $('#status'); $('form').ajaxform({ beforesend: function() { status.empty(); var percentval = '0%'; bar.width(percentval) percent.html(percentval); }, uploadprogress: function(event, position, total, percentcomplete) { var percentval = percentcomplete + '%'; bar.width(percentval) percent.html(percentval); //console.log(percentval, position, total); }, success: function(xhr) { var percentval = '100%'; bar.width(percentval) percent.html(percentval); }, complete: function(xhr) { status.html(xhr.responsetext); } }); })(); </script>
use $http.
example link:
$http.get('/someurl'). success(function(data, status, headers, config) { // callback called asynchronously // when response available }). error(function(data, status, headers, config) { // called asynchronously if error occurs // or server returns response error status. }); as showing progress, plugin looks promising: angular loading bar.
it work after including it.
angular.module('myapp', ['angular-loading-bar'])
Comments
Post a Comment