From the course: Building Applications with Angular, ASP.NET Core, and Entity Framework Core

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Angular service

Angular service

- [Instructor] Let's begin by creating an Angular service that will allow us to post new questions. Back in our editor, we'll create a new file in our app directory. We'll call it api.service.ts. And the first thing we'll do inside is create the class and export it. And just like components, we'll need to add a decorator. But unlike components, we'll need a different type of decorator called Injectable. We'll get access to that by importing Injectable from @angular core. And now, let's create the decorator. There's no properties to set for now inside our Injectable, so it just designates this API service class as an Injectable service. From our question component, we'll need to post a new question, so we'll need to have a postQuestion function inside our service. And of course, that will take a question as the value. Inside our postQuestion function, we'll need to send an HTTP request to our backend. To do that, we'll need to work with the HTTP module from Angular. So, let's go to the…

Contents