angular - 带有 Angular 7 的 SVG.js 3“没有兼容的调用签名”错误
问题描述
我正在使用 Angular 7 并且已经能够使用 SVG.js v2.* 但我无法让 SVG.js v3.* 工作。我做了两个 github 项目,第一个显示 SVG.js v2 工作angular7-svgjs2,第二个显示 SVG.js v3 不工作,唯一改变的是导入的库angular7-svgjs3
使用 SVG.js 2.7*(可行)
import { Component, AfterContentInit } from '@angular/core';
import * as SVGjs from 'svg.js';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements AfterContentInit {
title = 'angular7-svgjs2';
ngAfterContentInit () {
let draw = SVGjs('drawing');
let rect = draw.rect(100, 100);
}
}
使用 SVG.js 3.0.*(失败)
import { Component, AfterContentInit } from '@angular/core';
import * as SVGjs from '@svgdotjs/svg.js';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements AfterContentInit {
title = 'angular7-svgjs3';
ngAfterContentInit () {
let draw = SVGjs('drawing');
let rect = draw.rect(100, 100);
}
}
解决方案
svg.js v3 移至 esm。因此,您导入的是 esm 导出。
它不是您在 v2 中拥有的这种功能/对象混合。
所以,只导入你真正需要的:
import {SVG, find, Rect, whateveryouneed} from '@svgdotjs/svg.js'
var canvas = SVG().addTo('#drawing')
如您所见,新文档的初始化也发生了变化。
推荐阅读
- php - 如何将 PHP 5 正则表达式转换为 PHP 7 标准?
- android - Android gradle build:排除的java源文件被编译
- postgis - postgis中的最近邻搜索给出错误的结果
- apache-flink - 如何使用 flink-streaming 生成断电警报
- c++ - 如何在不使用属性的情况下指定对象
- polymer - zecat 的聚合物组件纸步进器存在后退导航问题
- php - 如何根据用户位置发送通知 oneSignal
- windows - 当字符串中有括号时如何用子字符串替换字符串
- docker - 来自守护进程的错误响应:获取 https://quay.io/v2/:未授权:未授权访问所请求的资源
- python - 带有python列表的FIXED If语句