0
votes

I am following this part of the loopback4 examples:

https://loopback.io/doc/en/lb4/Building-frontend-angular-application.html#step-5-create-a-component-that-calls-the-rest-endpoints

I am not editing anything from their original example todolist app. I use lb4 example todo to clone the application then I begin following their instructions.

In step 5, it states to add

// add a new function getTodos to get the todo list from the service getTodos(): void { this.todoService.findTodos().subscribe(todos => (this.todos = todos)); }

to the export class so it can fetch from the todo list from the service.

Problem is findTodos() is not defined by the service anywhere. The tutorial does not mention anything about constructing it or having to set it up.

As a newbie, I really am unsure how I would go about doing this. On another tutorial that follows these steps exactly the same

https://mobilediana.medium.com/building-a-frontend-application-with-loopback4-and-angular-e15c6fb48971

the Service defines findTodos(). It seems like open-api was supposed to auto generate this service then? However it looks like mine were created generic.

Instead of findTodos(), I just have find(), or instead of createTodos(), its just create() in my controller.services.

I cannot figure out what I missed up, I have done this 3 times now following step by step both of these tutorials and the findTodos() service is never auto generated for me.

You can see in the 2nd tutorial, the github shows their service having defined findTodos(). I do not want to just copy and paste it since I think I am a different version ahead of this tutorial now but I also want to learn why, since this is supposed to be a learning experience.

1
Changing findTodos() to just find() causes it to compile but the data wont bind to the application. Trying to figure out why now. Its probably related to this somehow. - user2457035

1 Answers

0
votes

Tutorial is missing pieces.

Take off the todos from the line in step 5 of the find function. Whatever reason unknown to me the open-api generated everything generic (findTodos as just find).

Then same step 5. They forgot to actually bind the data to the li tags so you need to add your {{}} bindings to actually show the data since it seems it just assumes youd understand.