如何在 angular7 的 html 模板中实现订阅

how can I implement subscribe in html template in angular7

getEmployee() 是我的服务页面中的一种方法,现在我希望在我的组件中使用 HTML 模板不订阅 showEmployee() 方法的员工列表。

 showEmployee(){
        this.employeeModel= this._empService.getEmployee();
  }

您需要 html 元素中的管道:

<p *ngFor="let data as employeeModel | async">
    <span> {{data.empName}}</span>
</p>
employeeModel : Observable<any>

或者如果它作为列表

employeeModel : Observable<any[]>=[];


showEmployee(){
        this.employeeModel= this._empService.getEmployee();
  }

在 Html 如果你有列表类型 Then

 <div *ngFor="let data as employeeModel | async">

    .... code for show data Like  {{data.property Name }}

    </div>

如果它是一个对象

<div> {{employeeModel | async}}</div>