Я пытаюсь создать библиотеку под углом, которая позволила бы мне обрезать изображение, для которого я хотел бы использовать canvas.
Я создаю библиотеку с "NG Generate Library".
когда я пытаюсь нарисовать свой холст, ничего не появляется.
crop-image.component.html:
<div class="container">
<canvas #canvas [width]="width" [height]="height" >
hello
</canvas>
<div>
<input type="file" accept="/image/*" (change)="onImageChange($event)">
</div>
</div>
crop-image.component.ts:
import {Component, ElementRef, Input, OnInit, ViewChild} from '@angular/core';
// @ts-ignore
@Component({
selector: 'lib-crop-image',
templateUrl: './crop-image.component.html',
styleUrls: ['./crop-image.component.css']
})
export class CropImageComponent implements OnInit {
imageUrl;
@Input() width = 500;
@Input() height = 500;
@ViewChild('canvas') canvasRef: ElementRef;
constructor() { }
ngOnInit() {
const ctx = this.canvasRef.nativeElement.getContext('2d');
ctx.moveTo(0, 0);
ctx.lineTo(100, 100);
ctx.stroke();
}
}