0

I just started learning AngularJS. My requirement is to upload the XML file from UI, which will further converted into JSON object. I had tried and google it but not found any proper solution. Please someone help me. thnx

this is my file and button code in html

<input type="file" id="importFile" mg-model="aclFile"/>
<input type="button" class="btn green" ng-click="uploadAclFile(aclFile)" value="Import" />

And this is angular js function

$scope.uploadAclFile = function(xmlData) {
alert("xmlData: " + doc);
}   
5
  • I just tried to call angularjs function with xml file argument and try to print it into console but it's giving undefined. Commented Aug 13, 2016 at 19:46
  • That means nothing. Put some code you've tried in there... Commented Aug 13, 2016 at 20:02
  • thnx for response, I have edited my question Commented Aug 13, 2016 at 20:09
  • Well you are referencing doc which is not a variable. Commented Aug 13, 2016 at 20:56
  • "You keep using that word. I do not think it means what you think it means." There is no such thing as a "JSON Object". Commented Aug 13, 2016 at 21:11

1 Answer 1

1

Yeppee I got it, Here What I did

For file input-

<input type="file" id="importFile" onchange="angular.element(this).scope().uploadXmlFile()"/>

JS-

$scope.uploadXmlFile = function(){
  var file = document.getElementById('importFile').files[0],
  reader = new FileReader();
  reader.onloadend = function(e){
      $scope.data = e.target.result;
      alert($scope.data);
  };
  reader.readAsBinaryString(file);
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.