下面是一个使用Angular 7复制和粘贴多个SVG图片的代码示例:
@ViewChild
装饰器来获取容器元素的引用,并定义一个变量来存储复制的SVG图片:import { Component, ViewChild, ElementRef } from '@angular/core';
@Component({
selector: 'app-svg-copy-paste',
templateUrl: './svg-copy-paste.component.html',
styleUrls: ['./svg-copy-paste.component.css']
})
export class SvgCopyPasteComponent {
@ViewChild('container', { static: true }) container: ElementRef;
copiedSvg: SVGSVGElement;
copy() {
this.copiedSvg = this.container.nativeElement.cloneNode(true);
}
paste() {
if (this.copiedSvg) {
this.container.nativeElement.appendChild(this.copiedSvg.cloneNode(true));
}
}
}
在上面的代码中,我们使用@ViewChild
装饰器获取了名为container
的HTML元素的引用,并将其存储在container
变量中。然后,我们定义了一个copiedSvg
变量来存储复制的SVG图片。copy
方法会将容器中的SVG图片进行复制,并将其存储在copiedSvg
变量中。paste
方法会将copiedSvg
中的SVG图片粘贴到容器中。
请注意,这只是一个简单的示例,只复制和粘贴了整个容器中的所有SVG图片。如果你想要更具体的控制,例如复制和粘贴特定的SVG元素,你需要调整代码来适应你的需求。