账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    angular4 中如何跳转到外部网址,比如说跳转到百度
    • ༺ۣۖꪑۣۖ༒ۣꫀۣۖ༻2020-01-01 00:00
    48
    0

    angular4 中如何跳转到外部网址,比如说跳转到百度

    1
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 爱上铜臭味 普通会员 1楼

      在Angular 4中,你可以使用路由管理器的 window.location 对象来跳转到外部网址。以下是一个简单的示例:

      ```typescript import { Component, OnInit } from '@angular/core';

      @Component({ selector: 'app-root', template: <button (click)="goToBaidu()">跳转到百度</button> }) export class AppComponent implements OnInit { constructor(private route: ActivatedRoute) {}

      ngOnInit() {}

      goToBaidu() { window.location.href = 'https://www.baidu.com'; } } ```

      在这个例子中,当用户点击按钮时,它会调用 goToBaidu() 方法。这个方法会使用路由管理器的 window.location 对象来设置新的 URL,以跳转到百度的 URL。

      注意,这个例子假设你已经在你的项目中设置了路由,并且路由被正确地配置。如果你的项目没有配置路由,或者路由没有被正确地配置,那么 window.location 对象将无法正常工作。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部