0
I deleted the question Variables and Scope Typescript because as a solution I made the validations I needed within the function of the event itself onload
then I think the solution changed the structure of the question, however I have a problem, the function always returns true
even when it enters the validations it should return false
:
isFileValid( file : File ) : boolean {
let image = new Image();
image.src = URL.createObjectURL( file );
image.onload = () : boolean => {
let imageH = image.height;
let imageW = image.width;
if ( imageH != this.maxheight || imageW != this.maxwidth ){
let notifications: Message = {
id: Math.random() * 10,
type: 'alert-danger',
button: true,
content: 'a imagem ' + file.name
+ " precisa ter exatamente as dimensões "
+ '<strong>${this.maxwidth}</strong>x<strong>${this.maxheight}px!`
};
this.notificationsService.add(notifications);
return false;
}
if ( file.size > ( this.maxsize * this.MB ) ) {
let notifications: Message = {
id: Math.random() * 10,
type: 'alert-danger',
button: true,
content: 'a imagem' + file.name
+ `ultrapassa o limite de ${ this.FormateBytes( this.maxsize * this.MB )}`
};
this.notificationsService.add(notifications);
return false;
}
return true;
}
return true;
}
how can I make for the call if (isFileValid(imagem) )
she returns true
or false
?
Thanks @Allan exactly what I needed!
– Hebert Lima