PhoneGap中文网
标题:
Angularjs4.0路由的动态传值
[打印本页]
作者:
幽梦林子
时间:
2017-8-11 12:07
标题:
Angularjs4.0路由的动态传值
Angularjs4.0路由的动态传值是如何操作的呢?我们可以通过以下两个步骤来完成:
1.配置动态路由
const routes: Routes = [
{path: 'home', component: HomeComponent},
{path: 'news', component: NewsComponent},
{path: 'newscontent/:id', component: NewscontentComponent},
{
path: '',
redirectTo: '/home',
pathMatch: 'full'
}
];
复制代码
2.获取动态路由的值
import { Router, ActivatedRoute, Params } from '@angular/router';
复制代码
constructor( private route: ActivatedRoute) {
}
复制代码
ngOnInit() {
console.log(this.route.params);
}
复制代码
欢迎光临 PhoneGap中文网 (http://bbs.phonegap100.com/)
Powered by Discuz! X3.2