Search code examples
angular7

how can I implement subscribe in html template in angular7


getEmployee() is a method in my service page and now I want employee list without subscribe showEmployee() method in my component using HTML template.

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

Solution

  • employeeModel : Observable<any>
    

    or If It as List

    employeeModel : Observable<any[]>=[];
    
    
    showEmployee(){
            this.employeeModel= this._empService.getEmployee();
      }
    

    In Html if You have List Type Then

     <div *ngFor="let data as employeeModel | async">
    
        .... code for show data Like  {{data.property Name }}
    
        </div>
    

    If Its an Object

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