Great! A gallery of images shows up. How does it work?
- In app.js inside the
app.config()method, we use Angular’s
$routeProviderto define the application routes.
- We used
.when()to map the URL
/to to the controller
HomeControllerand the template
HomeControlleruses the service js/services/photos.js to fetch the array of all photos from https://content.codecademy.com/courses/ltp4/photos-api/photos.json and stores it into
ng-repeatto loop through each item in the
photosarray and display each photo.
- Otherwise if a user accidentally visits a URL other than
/, we just redirect to
- Now when a user visits
/, a view will be constructed by injecting
<div ng-view></div>in index.html.
In app.js between the
.otherwise(), add another
.when() that maps the URL
/photos/:id to the controller
PhotoController and the template views/photo.html.
Visit http://localhost:8000/ and click on a photo. A detail page about that photo should appear.