【问题标题】:Angular component and service communication, didn't share valueAngular 组件和服务通信,没有共享价值
【发布时间】:2019-04-11 08:10:37
【问题描述】:

我有一个服务,它会从表单中得到一个 id。下一步是一个组件调用该服务。没关系,但不显示值。它的显示“未定义”会是什么问题?当我单击按钮时,它会显示未定义的消息,而不是我想要的 id。

服务:

getCompanyId(company) {
  this.selectedValue = company.id;
  alert("The Selected Company Id" + company.id);
}

组件:

getCompanyIdFromService(company): void {
  this.inputGroupService.getCompanyId(this.company);   
}

HTML:

<button mat-stroked-button [value]="company.id" (click)="getCompanyIdFromService(company)">{{company.id}}-{{company.company_name}}</button>

【问题讨论】:

    标签: angular


    【解决方案1】:

    传递 url 参数 company 而不是 this.company

    this.inputGroupService.getCompanyId(company);   
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-04
      • 2017-04-15
      • 1970-01-01
      • 2020-06-18
      • 1970-01-01
      • 2019-05-03
      • 2020-02-23
      相关资源
      最近更新 更多