相关疑难解决方法(0)

使用Angular 2新路由器更改页面标题

使用新路由器时,在浏览器中更改应用页面标题的正确方法是什么?

*使用Angular 2 CLI

angular

41
推荐指数
2
解决办法
3万
查看次数

如何在Angular 2中将路径数据导入App组件

我在我的应用程序路由模块中定义了一些路由数据,如下所示:

    const appRoutes:Routes = [
  {path: '', component: LoginComponent, data:[{PageName:"Login Page"}]}]
Run Code Online (Sandbox Code Playgroud)

我想全局获取数据,所以我使用app.component.ts来获取URL重定向相关信息,如下所示:

export class AppComponent {
  title = 'Welcome';
  constructor(public router: Router, public authenticationService: AuthenticationService) {
    this.router.events.subscribe(event => {
        console.log("Url",event.urlAfterRedirects);
        console.log("Page Name", router[PageName]); //Not working
      }
Run Code Online (Sandbox Code Playgroud)

我尝试注入ActivatedRoute,但每次重定向后都没有更新.

无论如何,我可以在哪里配置页面名称并在全球范围内获取它app.component.ts.

javascript angular-routing angular

9
推荐指数
3
解决办法
2万
查看次数

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 ×3

angular-routing ×2

javascript ×1

typescript ×1