变量通过订阅获得值,但不显示前端

发布于 2025-02-05 16:53:51 字数 2550 浏览 2 评论 0原文

我正在将Ludessetting组件路由到功能映射组件。 当我导航到功能映射组件中时,我通过订阅该字典将词典存储在命名feature22中。当我在控制台中打印时,我可以看到在功能22中存储了DIC,但此值未反映在HTML前端侧

component.feature-mappent.ts file

import { Component, OnInit } from '@angular/core';
import { CdkDragDrop, moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop';
import { AlldataService } from '../alldata.service';
import { HeadingService } from '../heading.service';

@Component({
  selector: 'app-feature-mapping',
  templateUrl: './feature-mapping.component.html',
  styleUrls: ['./feature-mapping.component.css']
})
export class FeatureMappingComponent implements OnInit {
  heading:string="Rule Setting"
  features22:any={}
  features33:any =[]

  constructor(
    private allDataService:AlldataService,
    private headingService:HeadingService) { 
  }

  ngOnInit(): void {
    this.headingService.heading.emit(this.heading)
    console.log()
    this.allDataService.features22.subscribe(
      (data:any)=>{
        for(var key in data)
        {
          this.features33.push(key)
          // this.features22[key] = data[key];
        }
        // this.features22.push(...data)
        this.features22=data
        console.log("this is in rule setting")
        console.log(this.features22)
        console.log(this.features33)
      }
    )
    console.log(this.features22)
    console.log(this.features33)
  }

}

component.feature-mappent.html文件

<div class="row-custom">
  <div class="section-heading1">Feature List</div>
  <div class="container1-main">
    <div> {{features33}}</div>
    <div> {{heading}}</div>
  <div class="container1" *ngFor="let feature of features22| keyvalue">
    {{feature.key}}
    <table class="table table-borderless">
      <thead>
        <tr>
          <th scope="col"></th>
          <th scope="col"></th>
        </tr>
      </thead>
      <tbody style="background-color: white;">
        <tr>
          <td scope="row" class="heading-tabledata">
            <div class="para">{{feature.key}}</div>
          </td>
          <td class="drag-tabledata">
            {{feature.value}}
          </td>
          
        </tr>
      </tbody>
    </table>
  </div>
</div>
</div>

[console] [1] [1]:https://i.sstatic.net/odyd9.png

[在前端] [2] [2]:https://i.sstatic.net/mgbno.png

如何在HTML前端显示功能22?

I am routing from rulessetting component to feature-mapping component.
When I navigated into feature-mapping component, i am storing a dictionary in variable named feature22 by subscribing it. When i am print in console i can see that in feature22 a dic is stored but this value is not reflecting in html frontend side

component.feature-mapping.ts file

import { Component, OnInit } from '@angular/core';
import { CdkDragDrop, moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop';
import { AlldataService } from '../alldata.service';
import { HeadingService } from '../heading.service';

@Component({
  selector: 'app-feature-mapping',
  templateUrl: './feature-mapping.component.html',
  styleUrls: ['./feature-mapping.component.css']
})
export class FeatureMappingComponent implements OnInit {
  heading:string="Rule Setting"
  features22:any={}
  features33:any =[]

  constructor(
    private allDataService:AlldataService,
    private headingService:HeadingService) { 
  }

  ngOnInit(): void {
    this.headingService.heading.emit(this.heading)
    console.log()
    this.allDataService.features22.subscribe(
      (data:any)=>{
        for(var key in data)
        {
          this.features33.push(key)
          // this.features22[key] = data[key];
        }
        // this.features22.push(...data)
        this.features22=data
        console.log("this is in rule setting")
        console.log(this.features22)
        console.log(this.features33)
      }
    )
    console.log(this.features22)
    console.log(this.features33)
  }

}

component.feature-mapping.html file

<div class="row-custom">
  <div class="section-heading1">Feature List</div>
  <div class="container1-main">
    <div> {{features33}}</div>
    <div> {{heading}}</div>
  <div class="container1" *ngFor="let feature of features22| keyvalue">
    {{feature.key}}
    <table class="table table-borderless">
      <thead>
        <tr>
          <th scope="col"></th>
          <th scope="col"></th>
        </tr>
      </thead>
      <tbody style="background-color: white;">
        <tr>
          <td scope="row" class="heading-tabledata">
            <div class="para">{{feature.key}}</div>
          </td>
          <td class="drag-tabledata">
            {{feature.value}}
          </td>
          
        </tr>
      </tbody>
    </table>
  </div>
</div>
</div>

[In console ][1]
[1]: https://i.sstatic.net/OdYD9.png

[In front-end ][2]
[2]: https://i.sstatic.net/mgbNo.png

How I can display feature22 in html front-end ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文