I am very new to Angular. I am trying to create a simple web application using Angular 2, where I allow users to select and image from their local computer. Then I want to display this image in the tag <img>. Later, perform actions on the image, for example, rotate, change the scale, change the width ... etc.
This is what I have in my component
@Component({
selector: 'image-container',
template: `
<input type="file" (change)="changeListner($event)" />
<img id="image"/>
`,
directives: [ImageActionsComponent]
})
export class ImageContainerComponent {
changeListner(event){
var reader = new FileReader();
reader.onloaded = function (e) {
var src = e.target.result;
document.getElementById("image").src = src;
};
reader.readAsDataURL(event.target.files[0]);
}
}
But this does not work at all. How to view image and update src attribute using Angular2?
I'm just trying to find out Angular. :)
Is there a better and easier way to do this?
source
share