我正在将数据从一个组件传递到另一个组件,但是在接收端,我正在获取对象格式的数据,如图所示,我只需要这些数字作为输出即可 enter image description here
这是我编写的代码
Component1.ts :-(我在这里导航至component2):-
this.router.navigate(['/operation', { questions:JSON.stringify(this.que),
answers:JSON.stringify(this.answers), level:this.level, operation:this.operation } ]);
Component2.ts :-(此组件接收)
answer = [];
que = [];
level=1
operation=1
constructor(private route: ActivatedRoute) {
}
ngOnInit() {
this.route.paramMap.subscribe(params => {
this.que = JSON.parse(params.get("questions"))
this.answer = JSON.parse(params.get("answers"))
this.level = parseInt(params.get("level"))
this.operation = parseInt(params.get("operation"))
});
}
Component2.html :(我在这里显示)
<div *ngIf="operation === 1">
<div class="app flex-row align-items-center">
<div class="container">
<div class="card-block">
<h4 class="card-title text-center">{{ i }}.) </h4>
<div *ngFor="let items of que| keyvalue">
<div *ngFor="let item of items| keyvalue">
{{ item.value | json }}
</div>
</div>
</div>
<h4 class="card-title text-center">
{{ answer }}
</h4>
</div>
如何获得仅数字结果