Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation on ko-image #22

Open
ephes opened this issue Oct 11, 2018 · 5 comments
Open

Documentation on ko-image #22

ephes opened this issue Oct 11, 2018 · 5 comments

Comments

@ephes
Copy link

ephes commented Oct 11, 2018

Hi *,

I spend half of today figuring out how to display an image on a konva layer in an angular app. Maybe an example in the documentation regarding image handling could save noobs like me a lot of time. But maybe it's just me. Anyway, here's what worked for me (disclaimer: since I'm a javascript beginner, maybe my approach is completely wrong):

import { Component, OnInit, EventEmitter } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

import { Observable, of } from 'rxjs';

// declare window to remove typescript warning
interface Window {
  Image: any;
}
declare const window: Window;

@Component({
  selector: 'app-detail',
  templateUrl: './app-detail.component.html',
  styleUrls: ['./app-detail.component.css']
})
export class DetailComponent implements OnInit {
  public configStage: Observable<any> = of({
    width: 700,
    height: 1000
  });

  public configImage:EventEmitter<any> = new EventEmitter();

  constructor(private route: ActivatedRoute) { }

  showImage(src: string) {
    const image = new window.Image();
    image.src = src;
    image.onload = () => {
      this.configImage.emit({
        image: image,
      })
    }
  }

  ngOnInit() {
    this.showImage('/path/to/image');
  }
}
@saucey
Copy link

saucey commented Nov 1, 2018

This screwed me up for a few hours, Brilliant Thanks!!!

@victacora
Copy link

Thank you :D

@torhy13
Copy link

torhy13 commented May 28, 2019

God bless you ephes! Thanks a LOT! Guys, please pay attention to this issue! This is important!

@bcrigler
Copy link

bcrigler commented Jan 14, 2020

Thank you for doing this... this and many other things need to be in the documentation, for sure.

Why did you use EventEmitter? Why not just use an Observable like the configStage property?

@viradia2
Copy link

Hi @ephes, I am new to Konva and writing code in Angular 6+ so I can load images. I have used ko-circle and other shapes but how to load images.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants