cart.component.ts
import { Component, OnInit } from '@angular/core';
import {Router} from '@angular/router'
@Component({
selector: 'cart',
template: `
<h1>购物车页面</h1>
<button (click)="handleClick()">去结算</button>
<a routerLink="/myOC/333">去结算</a>
`
})
export class CartComponent implements OnInit {
constructor(private myRouter:Router) { }
ngOnInit() { }
handleClick(){
this.myRouter.navigateByUrl('myOC/123');
}
}
orderconfirm.component.ts
import { Component, OnInit } from '@angular/core';
import {ActivatedRoute} from '@angular/router'
@Component({
selector: 'orderconfirm',
template: `
<h1>订单确认页面</h1>
<p>价格:{
{price}}</p>
`
})
export class OrderConfirmComponent implements OnInit {
price:number=0;
constructor(private myAR:ActivatedRoute) { }
ngOnInit() {
this.myAR.params.subscribe((result)=>{
console.log(result.price);
this.price=result.price;
})
}
}
app.router.ts
import {
CartComponent}
from
‘./demo16/cart.component’;
CartComponent}
from
‘./demo16/cart.component’;
import {
OrderConfirmComponent}
from
‘./demo16/orderconfirm.component’;
OrderConfirmComponent}
from
‘./demo16/orderconfirm.component’;
{
path:
‘myOC/:price’,
component:
OrderConfirmComponent},
path:
‘myOC/:price’,
component:
OrderConfirmComponent},
最后还需要在app.module.ts加些配置就好。
今天的文章angular 路由传参分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/6263.html