In your employees.component.ts file you import OnInit and OnDestoy and implement them.
On your class, you'll need a employeeCode string-property to store the value.
In ngOnInit you need to subscribe to the ApiService's GetLabelText with the needed parameters and in ngOnDestroy you'll need to unsubscribe.
import { OnInit, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs';
import { ApiService } from '../../services/api.service';
@component({
selector: '[app-employees]'
templateUrl: './employees.component.html',
})
export class EmployeesComponent implements OnInit, OnDestroy {
public labelSubscription: Subscription;
public employeeCode: string;
public constructor(private apiService: ApiService) { }
public ngOnInit() {
this.labelSubscription =
ApiService.GetLabelText('Employee', 'EmployeeId')
.subscribe((value) => this.employeeCode = value);
}
public ngOnDestroy() {
if (this.labelSubscription) {
this.labelSubscription.unsubscribe();
this.labelSubscription = null;
}
}
}
I also suggest you take a look at
Angular documentation and do a run on the
Heroes tutorial.