Skip to content

Commit 0cbb60e

Browse files
author
Martina Kraus
committed
adjust tasks
1 parent 761c132 commit 0cbb60e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+919
-523
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Material
44

5-
- [Workshop-Slides](https://bit.ly/2sCqPCB)
5+
- [Workshop-Slides](https://docs.google.com/presentation/d/1iHYJTqgePE94spv_HbLgTL40btSuK6QGLkLZRt0hkAM/edit?usp=sharing)
66

77
- [Angular Checklist](https://angular-checklist.io/default/checklist/architecture)
88

File renamed without changes.
File renamed without changes.

Task_1/Meet_the_AppComponent.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Meet the AppComponent
2+
3+
Let's warm up a bit and get familiar with our project environment.
4+
5+
- Open a terminal
6+
- Switch into the directory, where your Angular project is located
7+
- Run the Angular project by executing the command `npm start -- --open`
8+
- Open your Angular project in your preferred editor (VS Code, WebStorm, Sublime, ...)
9+
- Open the file _src/app/app.component.ts_.
10+
- Change the value of the property `title`.
11+
- Recognize that each change in a file causes an automatic reload in the browser
12+
13+
## Hints
14+
15+
### npm start
16+
17+
If you are not familiar with `npm` here is what `npm start -- --open` does.
18+
You will find a file called `package.json` in your Angular project.
19+
If you have a look into the file you will find a section called `scripts`.
20+
There you can see that the script `start` executes the Angular CLI command `ng serve`.
21+
That means `npm start` executes `ng serve`.
22+
23+
If you want to pass additional arguments to `ng serve` you can to that with npm to.
24+
By writing `--` you pass the following arguments to `ng serve`.
25+
That means `ng serve --open` is equivilant to `npm start -- --open`.
26+
27+
The argument `--open` opens the default browser after the compilation of your Angular project has been completed.

Task_10/Generate_two_Submodules.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Generate two Submodules
2+
3+
- Generate 2 sub Modules with a routing (we will learn later more about it)
4+
- about
5+
- books
6+
7+
- Move all book related code to the `books/`-folder.
8+
- _book.ts_
9+
- _book-card/_
10+
- _book-filter/_
11+
- Create a component that will take all the code of _AppComponent_: `ng generate component books/book`.
12+
- Open _app.module.ts_.
13+
- Remove all book related code.
14+
- Remove _BookCardComponent_ & _BookFilterPipe_ from declarations.
15+
- Add _BookModule_ and _AboutModule_ to the `imports`-Collection.
16+
- Transfer the content of _AppComponent_ to _BookComponent_ (only **inside** the class).
17+
- Transfer the content of _app.component.html_ to _book.component.html_.
18+
- Transfer the content of _app.component.scss_ to _book.component.scss_.
19+
- Check if all `import`-statements are correct.
20+
21+
- Generate a simple dummy Component `AboutComponent` inside `AboutModule`
22+
23+
Protip: Use the CLI Generator for this (--routing and -m)
24+
25+
## Hints
26+
27+
#### generate a whole module as submodule
28+
```
29+
ng g module books --routing -m app.module
30+
ng g module about --routing -m app.module
31+
```
32+
33+
#### generate a root-component in a subfolder for a module
34+
```
35+
ng g c about/about
36+
```
37+
#### app.component.html
38+
```
39+
<app-book-card></app-book-card>
40+
```
41+
#### books.module.ts
42+
```
43+
@NgModule({
44+
declarations: [BookComponent, BookCardComponent, BookFilterPipe],
45+
imports: [CommonModule],
46+
exports: [BookComponent]
47+
})
48+
export class BooksModule { }
49+
```
50+
51+
52+
[Solution](https://stackblitz.com/github/workshops-de/angular-workshop/tree/solve--filter-books)

Task_10/Observables.md

-19
This file was deleted.

Task_11/Local_API.md

-20
This file was deleted.

Task_11/NavigationComponent.md

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Generate a Material Sidebar Component
2+
3+
- Add angular Material to you Project (use all default values for the asked questions)
4+
- Include a [basic sidenav Material component](https://material.angular.io/components/sidenav/examples#sidenav-overview) inside the `app.component.html`
5+
- You will add a `MatSideNavContainer`, `MatSideNav` and `MatSideNavContent` since they are UI Components from Angular Material you need to import the Module inside your `AppModule` :
6+
`import {MatSidenavModule} from '@angular/material/sidenav';`
7+
8+
Info: the container contains the side-nav and the content. Inside the side-nav you need to add parameters for the Material UI Component to behave correctly:
9+
```html
10+
<mat-sidenav
11+
mode="side"
12+
opened>
13+
...
14+
</mat-sidenav>
15+
```
16+
17+
- To create a navigation inside the side-navigation component we need to add some more UI Components:
18+
```html
19+
// MaterialToolBar is a simple HeaderComponent
20+
// https://material.angular.io/components/toolbar/overview#toolbar-overview
21+
<mat-toolbar>Menu</mat-toolbar>
22+
23+
// MaterialNavigationListComponent
24+
// https://material.angular.io/components/list/overview#navigation
25+
<mat-nav-list>
26+
<a mat-list-item routerLink='/books'>Books</a>
27+
<a mat-list-item routerLink='/about'>About</a>
28+
</mat-nav-list></mat-sidenav>
29+
```
30+
Hint: Please ignore the `routerLink`-Attribute for now. We will come to it later.
31+
32+
33+
- Don't forget to import the new AngularMaterialModules as well:
34+
`MatListModule` and `MatToolbarModule`
35+
36+
37+
38+
39+
40+
## Hints
41+
42+
```sh
43+
ng add @angular/material
44+
45+
Use all default values
46+
```
47+
48+
To display the sidenav Component you will need to set a width of the `mat-side` Component
49+
50+
51+
52+
53+
54+
55+
56+
## Solution
57+
58+
```html
59+
<mat-sidenav-container class='sidenav-container'>
60+
<mat-sidenav
61+
class='sidenav'
62+
mode="side"
63+
opened>
64+
<mat-toolbar>Menu</mat-toolbar>
65+
<mat-nav-list>
66+
<a mat-list-item routerLink='/books'>Books</a>
67+
<a mat-list-item routerLink='/about'>About</a>
68+
</mat-nav-list></mat-sidenav>
69+
<mat-sidenav-content>
70+
<app-card-book></app-card-book>
71+
</mat-sidenav-content>
72+
</mat-sidenav-container>
73+
74+
```
75+
76+
```ts
77+
// app.module.ts
78+
import { MatSidenavModule } from '@angular/material/sidenav';
79+
import { MatButtonModule } from '@angular/material/button';
80+
import { MatIconModule } from '@angular/material/icon';
81+
import { MatListModule } from '@angular/material/list';
82+
import { MatToolbarModule } from '@angular/material/toolbar';
83+
84+
imports: [
85+
...
86+
87+
MatToolbarModule,
88+
MatButtonModule,
89+
MatSidenavModule,
90+
MatIconModule,
91+
MatListModule
92+
]
93+
```
94+
95+
```css
96+
// app.component.scss
97+
98+
.sidenav-container {
99+
height: 100%;
100+
}
101+
102+
.sidenav {
103+
width: 200px;
104+
}
105+
106+
.sidenav .mat-toolbar {
107+
background: inherit;
108+
}
109+
110+
.mat-toolbar.mat-primary {
111+
position: sticky;
112+
top: 0;
113+
z-index: 1;
114+
}
115+
116+
117+
```

Task_12/BookApi_Service.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Create a BookApiService
2+
- Create a service handling Book-API operations
3+
- Execute the following Angular CLI command: `ng generate service book/book-api`.
4+
- Implement the method `getAll()` that yields an array of Books.
5+
- Inject `BookApiService` into the _BookComponent_.
6+
- Get rid of the example books of _BookComponent_ by using the `BookApiService`
7+
8+
## Hints
9+
10+
#### Generate with ng-cli:
11+
12+
**Generate with Angular CLI**
13+
14+
```bash
15+
ng generate service book/book-api
16+
```
17+
18+
**Code:**
19+
20+
```typescript
21+
// book-list.component.ts
22+
constructor(private bookApi: BookApiService){}
23+
```
24+
25+
26+
[Solution](https://stackblitz.com/github/workshops-de/angular-workshop/tree/solve--create-a-BookApi-service)

Task_12/Component_LifeCycle.md

-23
This file was deleted.

Task_13/Async_Pipe.md

-13
This file was deleted.

Task_13/Observables.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Create an observable
2+
- Change the API of `getAll` returning `Observable<Book[]>` instead of `Book[]`.
3+
- Make use of the creation operator `of`.
4+
- Consume the Observable in the component.
5+
- Make sure that the books are still rendered.
6+
7+
## Hints
8+
9+
**imports**
10+
```typescript
11+
import { Observable, of } from 'rxjs';
12+
```
13+
14+
**getBooks()**
15+
```typescript
16+
return of(this.books);
17+
```
18+
19+
**Component**
20+
```typescript
21+
.subscribe(booksFromApi => /* assign to books */)
22+
```
23+
24+
[Solution](https://stackblitz.com/github/workshops-de/angular-workshop/tree/solve--create-an-observable)

Task_14/Local_API.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Load data from local API
2+
- Start our HTTP-Server `bookmonkey-api` in your shell.
3+
- Import the `HttpClientModule` in your `AppModule`.
4+
- Inject `HttpClient` via `constructor(private http: HttpClient)` in `BookApiService`
5+
- Load data from local API in `BookApiService` service via `http.get(URL)`
6+
7+
## Hints
8+
9+
## API starten
10+
11+
```bash
12+
# console session
13+
npm i -g bookmonkey-api
14+
bookmonkey-api
15+
# OR
16+
npx bookmonkey-api
17+
```
18+
19+
```typescript
20+
import { HttpClientModule } from '@angular/common/http';
21+
```
22+
23+
```typescript
24+
import { HttpClient } from '@angular/common/http';
25+
import { Observable } from 'rxjs';
26+
```
27+
28+
```typescript
29+
return this.http.get<Book[]>('http://localhost:4730/books')
30+
```
31+
32+
```typescript
33+
this.bookDataService.getBooks().subscribe(successFn);
34+
```
35+
36+
[Solution](https://stackblitz.com/github/workshops-de/angular-workshop/tree/solve--load-data-from-local-api)

Task_15/Async_Pipe.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Use the async pipe
2+
- Store the `getAll()`-Observable in a class property
3+
- Use the Observable and async pipe to subscribe and unsubscribe inside your `*ngFor`
4+
- **Warning**: This change affects the typing in the template
5+
- async returns either `Book[]` or `null`
6+
- You may need to adjust BookFilterPipe to deail with `null`-Values.
7+
8+
## Hints
9+
10+
```typescript
11+
// book-list.component.ts
12+
this.books$ = this.bookData.getAll();
13+
```
14+
15+
```html
16+
<!-- book-list.component.html -->
17+
*ngFor="let book of books$ | async | ..."
18+
```
19+
20+
[Solution](https://stackblitz.com/github/workshops-de/angular-workshop/tree/solve--use-the-async-pipe)
File renamed without changes.

0 commit comments

Comments
 (0)