Subtitles section Play video
-
Let's quickly talk about route params and how you use them.
-
So if I do a colon here and type something like message, I
-
can inject something here called route params into my
-
controller, and now I can simply say that our message is
-
$routeParams.message.
-
So that's going to parse this out of the URL, pass it along
-
as a parameter in the route, and then I can just look it up
-
by that key of message.
-
So if I refresh now, it's going to give me nothing
-
because there is no message here.
-
But if I say something like hello, it'll render out hello.
-
Or if I say something like bonjour, it'll render that out
-
simply because I'm grabbing the message off of the
-
$routeParams object.
-
Now, this isn't a typical scenario.
-
What you'd usually have is something like--
-
we'll say this is our map, and then you'd have like a
-
country, slash, state, slash, city, and then you can simply
-
have like a map page.
-
Let's build out our new message.
-
We'll have it be address, and we'll say our address is
-
$routeParams country plus comma.
-
So do it this way--
-
country, state, and city.
-
And then all we have to do is--
-
see if we refresh here, we got nothing because we need to
-
build out our URL like this is our map.
-
And the USA, my state is Utah, and I live in Orem--
-
please don't come and stalk me.
-
So it has address of USA, Utah, Orem because it took
-
these out of the URL and just simply provided them as route
-
parameters, and I can look them up this way.
-
So that's route parameters.
-
We'll see different ways of looking at them as we get into
-
things like redirect [? to. ?]