Patrick Patrick - 5 months ago 37
AngularJS Question

csv import only when save button is clicked (Plunker added)

Here is the Plunker. http://plnkr.co/edit/UQ4Pb94QzDbScnN7z2Vb?p=preview

as per this plunker, user selects a csv file. once file is selected, its content get displayed below it. its due to {{fileContent}} mentioned in the HTML code.

Instead of directly displaying below, i want user to click on save button. Once save button is clicked, i want the result to be displayed in console log instead of just below the select file button.

<html>
</html> //added this code so it allows me to post the question.


Any idea how to achieve this ?

Answer

Pass fileContent to save() function

html

<body ng-controller="MainCtrl">
    <p>Hello {{name}}!</p>
    <input type="file" file-reader="fileContent" />
    <button type="button" ng-click="save(fileContent);">Save</button>
    <div>{{fileContent}}</div>    
</body>

controller

$scope.save = function(data)
{
   console.log(data)
}
Comments