-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfive.html
126 lines (123 loc) · 6.08 KB
/
five.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Angular2 Part 2</title>
<link rel="icon" type="image/png" href="favicon.png">
<link rel="stylesheet" href="css/font-awesome.min.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<header>
<div class="logo"><a href="index.html"><img class="img-responsive" src="img/geekwise_owl.png" alt="geekwise owl logo"></a></div>
<nav class="navbar navbar-default">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav nav-pills navbar-nav pull-right">
<li><a href="index.html">Course Outline</a></li>
<li><a href="links.html">Handy Links</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Lessons <span class="caret"></span></a>
<ul class="dropdown-menu">
<li role="presentation"><a href="one.html">Day One</a></li>
<li role="presentation"><a href="two.html">Day Two</a></li>
<li role="presentation"><a href="three.html">Day Three</a></li>
<li role="presentation"><a href="four.html">Day Four</a></li>
<li role="presentation"><a href="five.html">Day Five</a></li>
<li role="presentation"><a href="six.html">Day Six</a></li>
<li role="presentation"><a href="seven.html">Day Seven</a></li>
<li role="presentation"><a href="eight.html">Day Eight</a></li>
<li role="presentation"><a href="nine.html">Day Nine</a></li>
<li role="presentation"><a href="ten.html">Day Ten</a></li>
<li role="presentation"><a href="eleven.html">Day Eleven</a></li>
<li role="separator" class="divider"></li>
<li role="presentation"><a href="final.html">Final Project</a></li>
</ul>
</li>
</ul>
</div>
</nav>
</header>
<div class="container">
<div class="row">
<div class="col-sm-12 text-center">
<h1>Day 5</h1>
</div>
</div>
<div class="row section"><!-- Concepts -->
<aside class="col-sm-3">
<h2>Concepts</h2>
</aside>
<main class="col-sm-9">
<ul class="points">
<li>Local Storage Service</li>
<li>Session Storage Service</li>
<li>Managing tokens with Session Storage</li>
</ul>
</main>
</div><!-- end Concepts -->
<div class="row section"><!-- Introductions -->
<aside class="col-sm-3">
<h2>Services</h2>
</aside>
<main class="col-sm-9">
<ul class="points">
<li>What is a service and what does it do?</li>
<li><a href="https://angular.io/guide/architecture#services-and-dependency-injection">Angular Documentation on services</a></li>
<li><small><a href="https://angular.io/tutorial/toh-pt4">Tour of Heroes Service Overview</a></small></li>
</ul>
<p>Great! So how do we make a service?</p>
<p>First, cd into the folder you want it in (services.)</p>
<p><a href="https://github.com/angular/angular-cli/wiki/generate-service">Creating a service with Angular CLI</a></p>
<pre><code>
$ ng g service localStorageService
</code></pre>
<small>Hint: If you want to change where the service is required, you must change that manually.</small>
<img src="../img/service-required.png" alt="" class="img-responsive">
</main>
</div><!-- end Introductions -->
<div class="row section"><!-- Updating the CLI -->
<aside class="col-sm-3">
<h2>Creating LocalStorageService and SessionStorageService</h2>
</aside>
<main class="col-sm-9">
<ul class="points">
<li>Take five minutes and generate two new services in your services folder: one for Local Storage and one for Session Storage.</li>
<li>Now that you've got those services, let's rewrite our UserService to store our user in Local Storage when we log in.</li>
</ul>
<h3>From this...</h3>
<pre><code>
login(user: any) {
return this.api.post('/userLogin', user).subscribe((res: any) => {
console.log(res);
this.router.navigateByUrl('/');
});
}
</code></pre>
<h3>To this...</h3>
<pre><code>
login(user: any) {
return this.api.post('/userLogin', user).subscribe((res: any) => {
this.localStorage.set('currentUser', res.user);
}, err => console.log(err), () => this.router.navigateByUrl('/'));
}
</code></pre>
<p>How could we handle logging our user out?</p>
</main>
</div><!-- end Updating the CLI -->
</div>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/script.js"></script>
</body>
</html>