Now I have a particular way of organizing my projects, it's not the best way because there is no best way; you have to come up with something that works for you and then force your team to follow your conventions because you are the smartest person on your team just like everyone else...
anyway, I like to put my root component into a root folder, I like to put my child components into a folder called components but i like to put my layout components into a layout folder. You maybe wondering why, well its just the way my brain works, doesn't mean that yours works this way; so let's start with creating a header.component and putting into the layouts folder.
First hit ctrl+c to stop your live dev server, then the angler command to generate a component is
ng generate component <Path/component.name> or ng g c <Path/component.name>
so in our case type in the following
ng generate component layout/header
and we should end up with the following
next lets open our header.componenet.ts file
what we need to make a note of is the selector, if you recall this is how we will put our component into our html, now open up our app.component.html file and add our component selector which we highlighted above for our header component.
now lets run our application and check it out ng server
ok so that's great, next let's open up our header.component.html file again and modify it
from this
to this
and navigate back to our application and bam!!! no refresh No restart our changes are automatically refreshed.
now let's create a simple grid for our game, first lets stop our applicaiton using ctrl+c in the terminal window, then next let's create a new component called grid under a components folder
ng generate component components/grid
and voila we have our grid component, so lets start with creating our ui, open up the Grid.componenet.html file and lets just do something simple, nine buttons each one of which will represent one of our tic tac to cells.
we are going to style them in you guessed it the style sheet, the interesting thing to notice is this (click) attribute, this is an angular event, it binds the click event of this control to an onMark method in our grid.component.ts file; so that seems like a natural place to look next.
all we did here is created a onMark(evetn: MouseEvnet, cellId:number): void method
we added a simple alert(cellId) body to our onMark method just to ensure that it works, so lets execute it and see.
sure enough if we click one of the little butons we get an alert with its corresponding cellId. finally lets make this look somewhat like a tic tac toe board. for that lets navigate to our grid.componenet.scss file and paste in the following
The above SCSS creates a grid out of our buttons; now if we take a look at our grid again
it's starting to look rather respectable, lets just quickly open up our app.component.html file and remove the div with hello world.
I think that is enough for this post, next we'll great a service to communicate with our api