0

I am a beginner both in Angular and programming generally, i am currently using angular and i need help on how to use selected data.

for example, i want to be able to use a personnel-number see the picture and send it to the backend. I need help on how to achieve this and would appreciate links to helpful learning resources. Thank you in advance

2
  • 1
    Hello. Adding relevant code snippet instead of image is more helpful. Commented Oct 7, 2020 at 11:56
  • If i get you, you're asking for help on how to get data into your application from an external source, if I'm correct, is the data in JSON format or from an image such as the one in your sample Commented Oct 7, 2020 at 12:14

1 Answer 1

1

Backend interaction with angular is carried out with HttpClient under @angular/common/http namespace. Make sure you have imported the HttpClientModule in your AppModule

After that you will make HttpClient service available in your component through Dependency Injection by declaring it as a parameter of your constructor. Something like

constructor(private httpClient: HttpClient){
}

HttpClient provide get, post, put, delete methods to interact with server, based on the serverside api you are calling. Angular official website has a very detailed documentation on the features of HttpClient. Please find the link

https://angular.io/guide/http

For example if you are making a get request, you'll simply have to provide the url of your backend service with parameter appended like this

this.httpClient.get<any>(`http://yourapiurlwillgohere?phoneNo=${this.phoneNumber}`).subscribe(res=>{
console.log('server side response is');
console.log(res);
});
Sign up to request clarification or add additional context in comments.

1 Comment

yes exactly. i can make a get- and post-request to receive data from database and to add data. that is the get. getBorrows(): Observable<Borrow[]> { const url = (${this.borrower_Url}); console.log(url); return this.httpClient.get<Borrow[]>(url).pipe(tap( _=> console.log("borrows loaded") )); };

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.