PhoneGap中文网

标题: Angularjs4.0路由的动态传值 [打印本页]

作者: 幽梦林子    时间: 2017-8-11 12:07
标题: Angularjs4.0路由的动态传值
Angularjs4.0路由的动态传值是如何操作的呢?我们可以通过以下两个步骤来完成:


1.配置动态路由

  1. const routes: Routes = [

  2.   {path: 'home', component: HomeComponent},
  3.   {path: 'news', component: NewsComponent},
  4.   {path: 'newscontent/:id', component: NewscontentComponent},
  5.   {
  6.     path: '',
  7.     redirectTo: '/home',
  8.     pathMatch: 'full'
  9.   }
  10.   
  11. ];
复制代码



2.获取动态路由的值

  1. import { Router, ActivatedRoute, Params } from '@angular/router';
复制代码

  1. constructor(  private route: ActivatedRoute) {

  2.   }
复制代码
  1. ngOnInit() {

  2.     console.log(this.route.params);
  3.   }
复制代码









欢迎光临 PhoneGap中文网 (http://bbs.phonegap100.com/) Powered by Discuz! X3.2