From the course: Ionic 4.0 Essential Training

Unlock the full course today

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

Generating services

Generating services - Ionic Tutorial

From the course: Ionic 4.0 Essential Training

Start my 1-month free trial

Generating services

- [Instructor] At some point in this course, we are going to need to access and fetch real data for our activity and then showcase this real data inside of our own application. In preparation for that, we will need to create a service for this. The reason why we would want to create a service for this is so that we don't have all that code in the typescript of our component. Now we can easily open up our tab1 typescript page, which is tab1 page.ts, and make all that fetch request here. However, this is not a good practice. The reason why this is not a good practice is any time we need to use the same data we then have to make the same http call all over again. Now to solve this problem, it's best that we use the service pattern by creating a service where we can put all that logic inside of that service so that we can call that service from anywhere in our application and access the same data. This is also good for testing so that when you want to test our code, we can just test it…

Contents