I have a factory and I want to change value of input. How could I do this ?
factory
var app = angular.module('starter');
app.factory('CameraFactory', ['$q', function($q, ngFileModel) {
var options = {
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: 0, // 0:Photo Library, 1=Camera, 2=Saved Photo Album
}
var onSuccess = function(imageData) {
window.resolveLocalFileSystemURI(imageData, function(fileEntry) {
//console.log(fileEntry.nativeURL);
ngFileModel.setPath(fileEntry.nativeURL);
});
var image = document.getElementById('smallimage');
image.src = imageData;
};
var onFail = function(e) {
console.log("onFail! " + e);
};
return {
getPicture: function() {
return navigator.camera.getPicture(onSuccess,onFail,options);
}
}
}]);
directive
var app = angular.module('starter');
app.directive('ngFileModel', function(){
return{
restrict:'A',
link: function(scope, element, attrs){
var field = attrs.ngFileModel;
scope.$watch('setPath', function(filePath){
field.value = filePath;
});
}
};
});
html
<div>
<img ng-src="img/ionic.png" id="smallimage" width="150" heigth="150">
<input type="file" ng-model='User.imageFile' id='imageFile' ng-file-model/>
<button class="button button-stable" ng-click="selectImage();">Imagem</button>