【发布时间】:2018-09-14 19:45:01
【问题描述】:
我在使用 Angular 4 中的路由时遇到了一点问题。你知道,当我尝试使用 navigate('root', data) 将数据从一个组件传递到另一个组件时,我刚刚收到了 [object Object],[object Object],[object Object]。
组件
export class FillRequestComponent implements OnInit {
constructor(private route: Router, private dataRoute: ActivatedRoute) { }
ngOnInit() {
const key: Products = this.dataRoute.snapshot.params['objectProducts'];
console.log(key);
}
界面
export interface Products {
color: string,
question: string,
surname: string,
icon: string,
selected: boolean,
transparent: boolean
}
发送方法
const data = {
category: this.optionSelected,
objectProducts: this.optionSelected === 'CREDIT' ? this.productCreditList :
this.productAccountsList
};
this.route.navigate(['/requests/fill', data]);
【问题讨论】:
-
我发现通过路线传递对象不是一种友好的模式,因为拥有路线的主要目的是让用户可以直接在那里导航。如果他们直接在那里导航,父母仍然能够传递对象吗?通常不会。