小编Ami*_*ten的帖子

Angular 6 - 无法检索静态数据

问题:在路由中定义的静态数据永远不会通过订阅 ActivatedRoute 的数据对象来检索。其他一切似乎都正常,数据对象不为空,但我无法从中获取数据。当我尝试从数据对象调试数据时,它输出“未定义”,当我尝试将它绑定到 UI 时,没有任何显示,但是当我查看 Chrome 中的 ActivatedRoute 消息时,它有数据。经过多次尝试,我很确定我的语法应该基于许多示例工作,所以 Angular 6 中的某些内容可能发生了变化,或者 Angular 有什么问题?

路线代码:

    const appRoutes: Routes = [
  {
    path: "article",
    redirectTo: "/article/partners",
    pathMatch: "full"
  },
  { 
    path: "article",
    children: [
      {
        path: "bawo",
        component: BawoArticleComponent,
        data: { title: 'BaWo' }
      },
      {
        path: "goldenhands",
        component: GoldenHandsArticleComponent,
        data: { title: 'Golden Hands' }
      },
      {
        path: "investors",
        component: InvestorsArticleComponent,
        data: { title: 'Investors' }
      },
      {
        path: "partners",
        component: PartnersArticleComponent,
        data: { title: 'Partners' }
      }
    ]
  }, …
Run Code Online (Sandbox Code Playgroud)

typescript angular-routing angular

3
推荐指数
1
解决办法
2075
查看次数

标签 统计

angular ×1

angular-routing ×1

typescript ×1