0

Im starting with Angular JS and trying to do this project I have, however I'm encountering some problems.

I know how to make routes using Angular JS the easy way, ie, if you have some specific .html files.

But how do you create something like a temporary .html file? Let me explain.

Let's say I have the main .html page of my CD store. You can make a quick search on my page and then you can click on a CD from a list of CD's in a vector. I want to create a route for that specific CD without having an .html file for each CD. When you click you'd get something like http:.../AbbeyRoad or http:.../AbbeyRoad.html.

Any suggestions?

1 Answer 1

1

What you're after is route parameters. You can do this:

.when('/Artist/:ArtistId/Album/:AlbumId', {
    templateUrl: 'album.html',
    controller: 'AlbumController'
 }

The : signifies that this is a parameter, and is passed in during navigation. You can then use that parameter in your controller how you see fit (making API calls, creating markup, etc.).

Like this -- here is your controller:

 .controller('ChapterController', function($scope, $routeParams) {
     $scope.params = $routeParams;
 })

and your view:

<div>
    Artist Id: {{params.ArtistId}}<br />
    Album Id: {{params.AlbumId}}
</div>

Take a look at the $route documentation.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot for the help! I will look into it :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.