window。打开不起作用的订阅角度

发布于 2025-02-12 03:40:52 字数 585 浏览 0 评论 0原文

订阅时如何在Angular中打开?我正在这样做,它行不通。

ngOnInit(): void {
    let code: string = null;
    this.route.paramMap.subscribe((result) => {
      code = result.get('code');
      if (code) {
        this.pageDataService.getQrLinks(Number(code)).subscribe(r => {
          if (r) {
            this.qrItems = r;
            this.showLinks = true;
            console.log (this.qrItems.length);
            if (this.qrItems.length === 1) {
             window.open(this.qrItems[0].contentLink);           
            }
          }
        });
      }
    });
  }

How can do window.open in angular when you subscribe to it? Im doing this one and it doesnt work.

ngOnInit(): void {
    let code: string = null;
    this.route.paramMap.subscribe((result) => {
      code = result.get('code');
      if (code) {
        this.pageDataService.getQrLinks(Number(code)).subscribe(r => {
          if (r) {
            this.qrItems = r;
            this.showLinks = true;
            console.log (this.qrItems.length);
            if (this.qrItems.length === 1) {
             window.open(this.qrItems[0].contentLink);           
            }
          }
        });
      }
    });
  }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜味超标? 2025-02-19 03:40:52

大多数浏览器会阻止弹出窗口在用户触发的事件处理程序之外被称为onclicksettimeout()可以有所帮助。

    setTimeout(() => {
      window.open('http://google.com');
    }, 1000);

Most browsers block popups if they are called outside of user-triggered event handlers like onclick. setTimeout() could help.

    setTimeout(() => {
      window.open('http://google.com');
    }, 1000);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文