クリップ機能を呼び出すボタンがあります。ngOnInitからその関数に値を渡す必要がありますが、できません。(たとえば) this.firstXに対して未定義のエラーが発生します。ngOnInit から関数に値を渡すにはどうすればよいですか?
export class AppAppComponent implements OnInit {
public firstX: number;
public firstY: number;
public lastX: number;
public lastY: number;
constructor(mdIconRegistry: MdIconRegistry) {
mdIconRegistry
.registerFontClassAlias('fontawesome', 'fa');
}
ngOnInit() {
let canvas = new fabric.Canvas('cLeft');
let src = "../../images/kupurSecond.jpg";
canvas.on('mouse:down', function (event) {
var position = canvas.getPointer(event.e);
this.firstX = position.x;
this.firstY = position.y;
});
canvas.on('mouse:up', function (event) {
var position = canvas.getPointer(event.e);
this.lastX = position.x;
this.lastY = position.y;
// ReLoading Image
loadImage(src, canvas, this.firstX, this.firstY, this.lastX, this.lastY);
});
loadImage(src, canvas);
};
public clip() {
console.log(this.firstX);
}
}