Я подписался на emitter и вижу вывод this.productNumber в консоли. но это не видно в файле html. Я использую его как {{productNumber}}
в html файле.
constructor(private http : HttpClientService) {
this.http.orderDetailEmitter.subscribe((response)=>{
this.productNumber=response;
console.log("productNumber"+this.productNumber);
});
}
HTML файл
<div>
<div class="mat-display-1">you have {{productNumber}} product</div>
<mat-form-field floatLabel="never" appearance="legacy" color="accent">
<mat-label> Name</mat-label>
<input matInput required>
<mat-hint align="end">min 5 characters</mat-hint>
</mat-form-field>
</div>
пожалуйста, дайте мне знать, если нужно больше деталей
код для обслуживания
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { EventEmitter } from '@angular/core';
export class Employee{
constructor(
public empId:string,
public name:string,
public designation:string,
public salary:string,
public isEditable : boolean
) {}
}
@Injectable({
providedIn: 'root'
})
export class HttpClientService {
orderDetailEmitter = new EventEmitter<number>();
constructor(
private httpClient:HttpClient
) {
}
getEmployees()
{
return this.httpClient.get<Employee[]>('http://localhost:8081/fetchEmployees');
}
public deleteEmployee(employee) {
return this.httpClient.delete<Employee>("http://localhost:8081/deleteEmployee" + "/"+ employee.emailid);
}
public createEmployee(employee) {
return this.httpClient.post<Employee>("http://localhost:8081/employees", employee);
}
public updateEmployee(employee){
return this.httpClient.post<Employee>("http://localhost:8081/updateEmployee", employee);
}
public createUser(user){
return this.httpClient.post("http://localhost:8081/registration",user);
}
}