Well, honestly this is my first attempt of working with pic upload in JS. I am working with an Angular project that needs to upload a pic from user and display it on a page. (Very much like we upload our profile pic on facebook, only difference being, this page will be downloaded as pdf later).
I was disappointed to see ng-model do not work with file type. I tried many things and finally made a directive that brings file to my controller (got help from here).
Now that I have file in my $scope.myPic variable. How do I go around using this file. How do I display it. . I tried binding the variable directly {{myPic}}, which didn't work . I tried using (#id).value(). Storing this in variable and binding, which didn't work.
There are other couples of thing I tried, but could not help myself out.
Can someone provide the way of binding image that are uploaded by users from their systems into HTML page in Angular. Any good links are more than appreciated ...
FYI:
My directive fn:
function uploadPicFn($parse) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
var model = $parse(attrs.picModel);
var modelSetter = model.assign;
element.bind('change', function(){
scope.$apply(function(){
modelSetter(scope, element[0].files[0]);
});
});
}
};
};
my html :
<div class="aw_textarea">
<label>That's me:{{home.myPic}}</label></br>
<input class="pd_txtarea" type="file" pic-model="home.myPic"/>
</div>