How to handle query parameters in angular 2

后端 未结 12 796
灰色年华
灰色年华 2020-11-27 03:41

In my routable component I have

@RouteConfig {
  {path: \'/login\',   name: \'Login\', component: LoginComponent}
}  

But how

12条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 04:22

    Angular2 v2.1.0 (stable):

    The ActivatedRoute provides an observable one can subscribe.

      constructor(
         private route: ActivatedRoute
      ) { }
    
      this.route.params.subscribe(params => {
         let value = params[key];
      });
    

    This triggers everytime the route gets updated, as well: /home/files/123 -> /home/files/321

提交回复
热议问题