I'm currently working with Angular 7 and I have managed to retrieve values from the backend. However, I am struggling to display these values in a textbox. Can anyone provide me with some suggestions on how to achieve this?
My tech stack includes Loopback and Angular 7.
file.component.ts
ngOnInit() {
let userId = window.localStorage.getItem("editUserId");
if(!userId) {
alert("Invalid action.")
this.router.navigate(['list-user']);
return;
}
alert(userId)
this.editForm = this.formBuilder.group({
id: [''],
name: ['', Validators.required],
firstName: ['', Validators.required],
lastName: ['', Validators.required],
age: ['', Validators.required],
salary: ['', Validators.required]
});
this.apiService.getUserById(+userId)
.subscribe( data => {
this.editForm.setValue(data);
//alert(data)
});
}
file.component.html
<div class="hidden">
<input type="text" formControlName="id" placeholder="id" name="id" class="form-control" readonly="true">
</div>
<div class="form-group">
<label for="name">User Name:</label>
<input type="text" formControlName="name" placeholder="name" name="name" class="form-control" id="name" readonly="true">
</div>