【问题标题】:In Angular component, link doesnt work with first time. How can it fix?在 Angular 组件中,链接第一次不起作用。怎么修?
【发布时间】:2022-12-03 05:05:47
【问题描述】:

当我尝试单击 Angular 中的一个数组 heroes 元素时 - 第一次单击不起作用,只有第二次才起作用。 怎么修?为什么会这样? 那是第一次使用的方法 onSelect5() 不起作用。 我在 github.com 上添加了所有代码的链接: [1]:https://github.com/site50/Angular-FETCH-an-fetch/tree/main/src/app

【问题讨论】:

    标签: angular typescript button hyperlink lazy-loading


    【解决方案1】:

    在文件 src/app/heroes/heroes.component.html 的第 7 行,你有

          <a routerLink="{{'../' + hero.id}}">
    

    但应该有

          <a routerLink="{{ hero.id }}">
    

    原因是 angular routing 试图去之前的路由,但是之前的根是这个页面,因此你第二次登陆这里,你在正确的路线上,可以去 '/{hero.id}' 页面(在路由文件中指定)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-03
      • 1970-01-01
      • 2017-12-31
      • 1970-01-01
      • 2019-10-05
      • 1970-01-01
      • 2015-09-22
      • 1970-01-01
      相关资源
      最近更新 更多