html - 新标签中的角度显示图像
问题描述
我的页面上有一个轮播图像查看器我希望用户在单击图像时会在浏览器的新选项卡中打开该图像,我编写了下面的代码,但它下载图像而不是显示它。
组件.ts:
openFile(url: string) {
window.open(url, "_blank");
}
组件.html
<ss-lightslider-slide *ngFor="let image of images"
[attr.data-thumb]="image.value"
[attr.data-src]="image.value"
[attr.data-id]="image.id"
class="ss-asset-thumbnail">
<img [src]="image.value" class="d-block w-100" title="{{image.name}}" alt="{{image.name}}" (click)="openFile(image.value)"/>
</ss-lightslider-slide>
我怎样才能让它在<img>
标签上点击它时显示图像而不是下载它?
解决方案
您可以创建一个窗口服务,并在单击图像时写下类似
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root',
})
export class WindRefService {
constructor() {}
getNativeWindow() {
return window;
}
}
onView() {
this.nativeWindow.open(image);
}
您可能需要寻找 getNativeWindow() 用于您的案例
推荐阅读
- npm - 如何修复需要 semver-major 依赖更新的 npm 漏洞?
- java - 如何让杰克逊找到我的密钥解串器?
- java - ArrayList 列表=新的 ArrayList(); 列表列表=新的 ArrayList(); 两者有什么区别?
- python - 使用 Python Selenium 在 click() 后提取内容
- python - 一个点积示例中的“矩阵未对齐”,但在另一个示例中工作正常
- flutter - Flutter:通过键盘隐藏警报对话框
- css - 应用于一个元素而不是另一个元素时的混合混合模式工作
- javascript - 使用 html、javascript 和 css 从表单中为每个用户输入在 div 中制作特定的错误消息
- python - Python线程类实例更改所有实例的变量
- java - 需要 Eclipse IDE 插件开发帮助:重命名 Active Editor、TextEditor 的文件资源