我正在访问一个 API,在 json 对象中,我在清理图像字符串后获取 svg 图像字符串
this.apiService.receiveImageAsNonJSON("http://localhost:8080/icreate/getViewImagesBySubCategory", subCatName).subscribe(viewImageDataSet => {
this.masterImageList = viewImageDataSet;
var masterImageListLength = this.masterImageList.length;
// Calculate number columns , number of rows is fixed at 7
let colCount = Math.ceil(masterImageListLength / 7);
for (var index = 0; index < masterImageListLength; index++) {
// Sanitize image string
this.masterImageList[index] = this.sanitizer.bypassSecurityTrustHtml(this.masterImageList[index] as string);
});
现在我使用 [outerHTML] 属性以 html 显示图像。我正在获取 svg 的实际大小,但我想要自定义大小。如何解决它。请任何人给予光明。提前谢谢你--Midde
这里我附上了屏幕截图,并在蓝色圆圈中标记了我要自定义的高度和宽度。 输出屏幕截图
它很丑陋,但你可以尝试 NgStyle 指令(https://angular.io/api/common/NgStyle)
您可以尝试以下代码吗:
组件.ts
sizeOuter():string{
var resizeComment:number;
resizeComment=window.innerWidth-45/10;
return resizeComment + 'px';
}
heightOuter():string{
var resizeComment:number;
resizeComment=window.innerHeight-45/10;
return resizeComment + 'px';
}
html:
<div [ngStyle]="{'width': sizeOuter(),'height':heightOuter()}" [outerHTML]="image.thumbNailImage">i j</div> </div>