Skip to content

Instantly share code, notes, and snippets.

@wjuniorw
Last active February 20, 2023 03:10
Show Gist options
  • Select an option

  • Save wjuniorw/bffb1a5cc4ef6e69c92270e31050bd6a to your computer and use it in GitHub Desktop.

Select an option

Save wjuniorw/bffb1a5cc4ef6e69c92270e31050bd6a to your computer and use it in GitHub Desktop.
(function () {
'use strict';
angular
.module('app')
.directive('imgUpload', Upload)
function Upload () {
var directive = {
restrict: 'AE',
scope: {
imagem1: '='
},
replace: true,
transclude: true,
controller: uploadCtrl,
link: linkFunc,
bindToController: true
}
return directive
function linkFunc (scope, el, attr, ctrl) {
el.on('change', function(file) {
var FR = new FileReader();
FR.onload = function(file) {
//scope.imagem contem o arquivo em base..
scope.imagem = file.target.result;
scope.$apply();
console.log('imagem capturada');
scope.getImagem();
};
FR.readAsDataURL(scope.imgName = this.files[0] );
})
}
uploadCtrl.$inject = ['Myservice', '$scope']
function uploadCtrl (Myservice, $scope) {
$scope.getImagem = function () {
Myservice.myFile.push($scope.imagem);
}
};
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment