加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – 当相同组件加载不同数据时,不会调用ngOnInit

发布时间:2020-12-17 09:41:39 所属栏目:安全 来源:网络整理
导读:我有一个有角度的2应用程序,我使用路由器在视图之间导航,就像其他人一样.以下是我的特定组件的路径: { path: 'home/view1/:viewID',component: ViewComponent,children: [ { path: 'pane/:paneId/section/:sectionId',component: SectionEditComponent },{
我有一个有角度的2应用程序,我使用路由器在视图之间导航,就像其他人一样.以下是我的特定组件的路径:
{
    path: 'home/view1/:viewID',component: ViewComponent,children: [
        { path: 'pane/:paneId/section/:sectionId',component: SectionEditComponent },{ path: '**',component: ViewEditComponent }
    ]
},

现在,我在ViewComponent上有两个按钮,为section1和section2加载SectionEditComponent.

Path1:pane / 1 / section / 1
路径2:窗格/ 1 /部分/ 2

ViewComponent模板:

<div class="col-md-8" style="background-color: white; height: 100%">
       <button (click)="loadPath(1)">Path1</button>
       <button (click)="loadPath(2)">Path2</button>
       <router-outlet></router-outlet>
   </div>

现在,当我从同一ViewComponent中的Path1-> Path2或Path2-> Path1导航时,不会调用ngOnInit(),因此不会加载新路径,即使url实际上根据新的部分ID更改.

这是已知的还是预期的行为?有什么我做错了吗?

注入路径并订阅参数更改
constructor(route:ActivatedRoute) {
  route.params.forEach(params => {
    myInit(params['paramId']);
  });
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读