|
| 1 | +##$routeProvider |
| 2 | +- Routes allow you to add multiple page functionality to your app. |
| 3 | +- Views are triggered via the location hash. |
| 4 | +- Routes are set up on the application configuration: |
| 5 | + |
| 6 | +```javascript |
| 7 | +app.config(["$routeProvider", function($routeProvider) { |
| 8 | + $routeProvider |
| 9 | + .when("/wines", { |
| 10 | + templateUrl: "templates/wine-list.html", |
| 11 | + controller: "wineCtrl" |
| 12 | + }) |
| 13 | + .otherwise({ |
| 14 | + redirectTo: "/wines" |
| 15 | + }); |
| 16 | +}]); |
| 17 | +``` |
| 18 | + |
| 19 | +- In order to use this new ngRoute module however it has to be one of our dependencies in our module setup: |
| 20 | + |
| 21 | +```javascript |
| 22 | +var app = angular.module("wineApp", ["ngRoute"]); |
| 23 | +``` |
| 24 | + |
| 25 | +#####Accessing route parameters |
| 26 | + |
| 27 | +- In order to access parameters that are passed into a URL, you will need to inject $routeParams into your controller: |
| 28 | + |
| 29 | +```javascript |
| 30 | +app.controller("wineCtrl", function($scope, $http, $routeParams) { |
| 31 | + console.log($routeParams.id); |
| 32 | +}); |
| 33 | +``` |
| 34 | + |
1 | 35 | ##Wine List Lab Part 2
|
2 | 36 | - In this part we will use routing to full data about a specific wine and render the edit page.
|
3 | 37 | - Here are the steps you will need to follow:
|
4 | 38 | - Step 1: Create a route to `/edit/:id`.
|
5 | 39 | - Step 2: Use the route parameter to make a GET request to `http://daretodiscover.herokuapp.com/wines/:id`.
|
6 | 40 | - Step 3: Display wine data in the form on edit.html.
|
7 |
| - - Step 4: On submit of the form create a PUT request to the same URL as above to update the wine record. |
8 |
| - |
9 |
| -##ngAnimate |
10 |
| -- ngAnimate is a module that allows us to perform animations on elements selectively. |
11 |
| -- This functionality requires the ngAnimate module from the Angular extras. |
12 |
| -- Let's take a look at the documentation [here](https://docs.angularjs.org/api/ngAnimate/). |
13 |
| -- Animations work by applying the `.ng-enter`, `.ng-enter-active`, `.ng-leave`, or `.ng-leave-active` classes on any of your existing classes. |
14 |
| -- Your classes should implement some sort of CSS3 animation. |
15 |
| -- Let's try this out with some pre-built css classes to help us out: https://github.com/Augus/ngAnimate. |
16 |
| - |
17 |
| -##Wine List Lab Part 3 |
18 |
| -- In this part of the lab we will implement some animations between views. |
19 |
| -- Use your existing application and create an animation between the wine list and the edit view. |
20 |
| -- Experiment using different CSS3 properties. |
| 41 | + - Step 4: On submit of the form create a PUT request to the same URL as above to update the wine record. |
0 commit comments