角度数据作为对象接收

时间:2019-11-08 21:43:33

标签: angular

我正在将数据从一个组件传递到另一个组件,但是在接收端,我正在获取对象格式的数据,如图所示,我只需要这些数字作为输出即可 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 }}.) &nbsp;&nbsp;</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">
       &nbsp;&nbsp;&nbsp;   {{ answer }}
   </h4>
</div>

如何获得仅数字结果

0 个答案:

没有答案