我正在尝试在 Angular 项目中使用cropperjs 库。文档中的裁剪器示例在普通静态网页上运行良好(简单<script>
的 index.html 带有 js 标记和指向cropper.css 文件的链接)。
但由于某种原因,这不起作用。Cropper 似乎已加载(console.log(Cropper)
执行该功能),并且有一些功能,但看起来缺少样式。
cropper.component.ts
import {Component} from "@angular/core";
var foo = require('cropperjs/dist/cropper');
@Component({
selector: "cropper",
template: `
<div>
<img id="image" src="https://dl.dropboxusercontent.com/s/vyeh3vqc93hbye4/Capture%20d%27%C3%A9cran%202016-05-27%2017.14.53.png?dl=0">
</div>
`,
styleUrls: ['../styles/cropper.css', '../styles/cropper.component.css']
})
export class CropperComponent implements OnInit{
ngOnInit(){
var image = document.getElementById('image');
var cropper = new Cropper(image, {
aspectRatio: 16 / 9,
crop: function(e) {
console.log(e.detail.x);
console.log(e.detail.y);
console.log(e.detail.width);
console.log(e.detail.height);
console.log(e.detail.rotate);
console.log(e.detail.scaleX);
console.log(e.detail.scaleY);
},
});
}
}