Created
February 13, 2017 10:24
-
-
Save KeithNdhlovu/9a67c9cce563778d0cba67ab626a559e to your computer and use it in GitHub Desktop.
How to attach ng-model on an input type=file
This file contains hidden or 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
var clientInformationApp = angular.module('clientInformationApp', [], function($interpolateProvider) { | |
$interpolateProvider.startSymbol('<%'); | |
$interpolateProvider.endSymbol('%>'); | |
}).directive("fileread", [function () { | |
return { | |
scope: { | |
fileread: "=" | |
}, | |
link: function (scope, element, attributes) { | |
element.bind("change", function (changeEvent) { | |
var reader = new FileReader(); | |
reader.onload = function (loadEvent) { | |
scope.$apply(function () { | |
scope.fileread = loadEvent.target.result; | |
}); | |
} | |
reader.readAsDataURL(changeEvent.target.files[0]); | |
}); | |
} | |
} | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment