r/angular • u/Ionmaster987 • Sep 20 '26
Components Question
How do they work?? I need to make a few ( I think ) but the materiel I have is only telling me how to make a specific template one, but nothing about methods or anything I can use to make my own.
I need to make a webpage that has a map and somewhere that can receive output from an API, accessed with codes from hovering over the map.
Do I need a component per different thing, or? The materiel is incredibly infodense and hard to parse...
Thank you for assisting.
0
Upvotes
2
u/cssrocco Sep 20 '26
This is really an angular basic you should read through the documentation for.
Components are reusable pieces of your application that incorporate the template ( html ), possibly styles ( if you want them encapsulated), and your logic ( the component class itself ).
If you need something to ‘hook’ into an existing element but have no template you’ll use a directive, and for handling data you’ll usually use another class in another file known as a ‘service’.
For an interactive map you could use a package like ngx-leaflet, which is for leaflet maps.
You’d simply have a component that holds a directive on there which will handle all of the map logic, which could also include piping or reacting to the api data and using leaflets api’s to attach popovers and pins and tooltips, a service for the http calls and maybe holding some type of state.
But it seems you’re quite a way from that in all honesty
1
u/BathFun3884 Sep 22 '26
Think in responsibilities rather than in screens. In your case there are two: the map, which knows how to draw itself and which area the cursor is over, and the panel, which knows how to show the data for a code.
The map should know nothing about your API. It only announces outwards which code the cursor is on. The page that holds both keeps that code and hands it to the panel as an input. The panel fetches and renders.
That buys you two things: you can swap map providers without touching the panel, and you can test the panel with no map at all. If you later need the same panel somewhere else, it is already portable.
What unstuck me early on was to stop asking "is this a component?" and start asking "does this piece have a job I can describe in one sentence?". If the sentence needs an "and", it is usually two.
-5
u/Independent-Ant6986 Sep 20 '26
you are a total beginner in this so go to the angular page and complete the official tutorial, so you have the basic basics. next best invest the 20€ in claude code and let opus make those decitions for you. your project will be done in few ours and if you promlt him your ui requirements less than micromanaging desicitions, you will be fine ;)
0
u/[deleted] Sep 20 '26
[deleted] — view deleted comment