首页 > 解决方案 > 作为对象接收的角度数据

问题描述

我正在将数据从一个组件传递到另一个组件,但在接收端,我正在获取对象格式的数据,如图所示,我只需要这些数字作为输出 ,在此处输入图像描述

这是我写的代码

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>

我怎样才能获得仅数字的结果

标签: angular

解决方案


推荐阅读