One way to retrieve data from a database and populate it into an input box is shown below:
Retrieving service
getStudentAddress() {
const id = sessionStorage.getItem('userId');
return this.http.get('http://localhost:8080' + '/student/' + id);
}
The getStudentAddress()
function will fetch student data in an array format.
https://i.sstatic.net/0casF.png
To automatically display this data on an input box when the page loads, you can use the following method in your component:
ngOnInit() {
// Here you can set the value from the database using setValue or patchValue
this.studentForm.setValue({
s_pNumber: '1234',
s_address: '123',
s_address2: '123',
s_pCode: '123',
s_city: '123',
s_state: '123',
s_country: '123'
});