angular4中组件之间页面切换的数据传递,通过路由传递数据

例如在表格中有一个详情按钮,跳转到另外一个页面,

angular4中组件之间页面切换的数据传递,通过路由传递数据_第1张图片

首先需要在所在页面和跳转页面引入路由组件和跳转界面路由组件

selectMsg(productID:number,productName:any,productCome:any){

// 跳转页面

return this.router.navigate(['product-element',{"productID":productID,"productName":productName,"productCome":productCome}]);

}

product-element'是需要跳转的路由,{}里面是传递的值,这个值可已通过你点击事件来获取

例如表格中的数据data

angular4中组件之间页面切换的数据传递,通过路由传递数据_第2张图片

跳转的页面也需要引入路由配置

import {Router,ActivatedRoute} from '@angular/router';

然后在constructor中进行数据的获取

angular4中组件之间页面切换的数据传递,通过路由传递数据_第3张图片

这样就可以使得一个页面的数据传递到另一个界面。

 

你可能感兴趣的:(angular4-6开发)