Skip to content

Commit d7cd1eb

Browse files
committed
細かい内容の修正
1 parent bd42ce9 commit d7cd1eb

File tree

1 file changed

+34
-44
lines changed

1 file changed

+34
-44
lines changed

README.md

Lines changed: 34 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ npm i -S @angular/material @angular/cdk
103103
スタイルテーマを追加
104104
```styles.scss
105105
@import "~@angular/material/prebuilt-themes/indigo-pink.css";
106+
md-list-item {
107+
overflow: hidden;
108+
}
106109
```
107110

108111
app.moduleに使いたいモジュールをimportしておくよ!
@@ -157,7 +160,7 @@ export class AppModule { }
157160

158161
ToDoを保持するServiceを作りますよ!
159162
```
160-
ng g service shared/services/todo
163+
ng g service shared/services/todo/todo
161164
```
162165

163166
> WARNING Service is generated but not provided, it must be provided to be used
@@ -166,22 +169,22 @@ ServiceはModuleに勝手に読み込まれないので注意です。
166169

167170
Serviceで使う型定義書くファイルも一緒に作りましょう。
168171
```
169-
ng g interface shared/models/todo
172+
ng g interface shared/services/todo/todo model
170173
```
171174

172-
```shared/models/todo.ts
175+
```shared/services/todo/todo.model.ts
173176
export interface TodoItem {
174-
id: number,
175-
state: string,
176-
value: string
177+
id: number;
178+
state: string;
179+
value: string;
177180
}
178181
```
179182

180183
作った型定義を読み込むよ!
181184

182185
```shared/services/todo.service.ts
183186
import { Injectable } from '@angular/core';
184-
import { TodoItem } from '../models/todo'; // <-追加
187+
import { TodoItem } from './todo.model'; // <-追加
185188

186189
@Injectable()
187190
export class TodoService {
@@ -195,7 +198,7 @@ export class TodoService {
195198
import { Injectable } from '@angular/core';
196199
import { Observable } from 'rxjs/Observable';
197200
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
198-
import { TodoItem } from '../models/todo';
201+
import { TodoItem } from './todo.model';
199202

200203
@Injectable()
201204
export class TodoService {
@@ -313,7 +316,7 @@ ng g pipe shared/pipes/todoSearch
313316

314317
```shared/pipes/todo-search.ts
315318
import { Pipe, PipeTransform } from '@angular/core';
316-
import { TodoItem } from '../models/todo';
319+
import { TodoItem } from '../services/todo/todo.model';
317320

318321
@Pipe({
319322
name: 'todoSearch'
@@ -332,32 +335,20 @@ export class TodoSearchPipe implements PipeTransform {
332335
```home/home.component.ts
333336
import { Component, OnInit } from '@angular/core';
334337
import { Observable } from 'rxjs/Observable';
335-
import { TodoService } from '../shared/services/todo.service';
336-
import { TodoItem } from '../shared/models/todo';
338+
import { TodoService } from '../shared/services/todo/todo.service';
339+
import { TodoItem } from '../shared/services/todo/todo.model';
337340

338341
import { MdRadioChange } from '@angular/material';
339342

340-
import { slideFadeIn, slideFadeOut } from '../app.animations';
341-
import {
342-
transition,
343-
trigger,
344-
state,
345-
style,
346-
stagger,
347-
query,
348-
group,
349-
animateChild
350-
} from '@angular/animations';
351-
352343
@Component({
353-
selector: 'et-home',
344+
selector: 'app-home',
354345
templateUrl: './home.component.html',
355346
styleUrls: ['./home.component.scss']
356347
})
357348
export class HomeComponent implements OnInit {
358349
public list: Observable<TodoItem[]>;
359-
public searchWord: string = '';
360-
public filterState: string = 'all';
350+
public searchWord = '';
351+
public filterState = 'all';
361352
public filterItems = [
362353
{
363354
name: 'all',
@@ -429,6 +420,8 @@ export class HomeComponent implements OnInit {
429420
</md-radio-group>
430421
</form>
431422
423+
<button md-raised-button color="warn" (click)="clearComplete()">完了したタスクを削除</button>
424+
432425
<md-list *ngIf="(list | async | todoSearch : searchWord) as items">
433426
<md-list-item *ngFor="let item of items" (click)="changeState(item.id)">
434427
<md-checkbox md-list-icon [checked]="item.state === 'complete'" (click)="$event.preventDefault()"></md-checkbox>
@@ -439,13 +432,8 @@ export class HomeComponent implements OnInit {
439432
</p>
440433
</md-list-item>
441434
</md-list>
442-
443-
<button md-raised-button color="warn" (click)="clearComplete()">完了したタスクを削除</button>
444435
```
445436

446-
ここまではこちらのリポジトリにあります。
447-
https://github.com/frontainer/practice-angular-animations
448-
449437
---
450438

451439
## アニメーション基本
@@ -471,15 +459,15 @@ import {
471459
state('complete', style({
472460
backgroundColor: '#eee'
473461
})),
474-
transition('todo => complete', [
462+
transition('* => complete', [
475463
style({
476464
backgroundColor: '#fff'
477465
}),
478466
animate('200ms ease-out', style({
479467
backgroundColor: '#eee'
480468
}))
481469
]),
482-
transition('complete => todo', [
470+
transition('* => todo', [
483471
style({
484472
backgroundColor: '#eee'
485473
}),
@@ -493,8 +481,8 @@ import {
493481
})
494482
```
495483

496-
```home/home.component.html
497-
<md-list-item *ngFor="let item of items" (click)="changeState(item.id)" [@stateEffect]="item.state">
484+
```home/home.component.html 21行目
485+
<md-list-item *ngFor="let item of items" (click)="changeState(item.id)" [@stateEffect]="item.state">
498486
```
499487

500488
`[@stateEffect]="item.state"`を追加しました。
@@ -522,7 +510,7 @@ import {
522510
4.2で追加されたanimation関数を使うことで共通に使うアニメーションの定義をすることができます。パラメータで実行時間などは変更できるので、ある程度汎用的に作れる様になりますよ!
523511

524512
```
525-
ng g class app.animations.ts
513+
ng g class app.animations
526514
```
527515

528516
代表的なフェードイン・フェードアウトを書いてみましょう。
@@ -552,12 +540,10 @@ export const slideFadeIn = animation([
552540
export const slideFadeOut = animation([
553541
style({
554542
opacity: 1,
555-
transform: 'translateX(0)',
556543
height: '*'
557544
}),
558545
animate('{{time}} {{easing}}', style({
559546
opacity: 0,
560-
transform: 'translateX(-2%)',
561547
height: 0
562548
}))
563549
], {
@@ -591,9 +577,9 @@ componentのanimationsにアニメーションを定義を追加しますよ!
591577
selector: 'et-home',
592578
templateUrl: './home.component.html',
593579
styleUrls: ['./home.component.scss'], // <- 「,」忘れずに
594-
// 追加ここから
595580
animations: [
596581
// ...略
582+
// 追加ここから
597583
trigger('slideFade', [
598584
transition(':enter', [
599585
useAnimation(slideFadeIn)
@@ -602,12 +588,12 @@ componentのanimationsにアニメーションを定義を追加しますよ!
602588
useAnimation(slideFadeOut)
603589
])
604590
])
591+
// 追加ここまで
605592
]
606-
// 追加ここまで
607593
})
608594
```
609595

610-
```home/home.component.html
596+
```home/home.component.html 21行目
611597
<md-list-item *ngFor="let item of items" (click)="changeState(item.id)" [@stateEffect]="item.state" @slideFade>
612598
```
613599

@@ -644,6 +630,7 @@ import {
644630
stagger // <- 追加
645631
} from '@angular/animations';
646632
// ...略
633+
// slideFade置き換えここから
647634
trigger('slideFade', [
648635
transition('* => *', [
649636
query(':leave', [
@@ -656,9 +643,10 @@ trigger('slideFade', [
656643
], { optional: true })
657644
])
658645
])
646+
// slideFade置き換えここまで
659647
```
660648

661-
```home/home.component.html
649+
```home/home.component.html 20行目
662650
<md-list *ngIf="(list | async | todoSearch : searchWord) as items" [@slideFade]="items">
663651
<md-list-item *ngFor="let item of items" (click)="changeState(item.id)" [@stateEffect]="item.state">
664652
```
@@ -690,9 +678,10 @@ import {
690678
} from '@angular/animations';
691679

692680
// ...略
681+
// slideFade置き換えここから
693682
trigger('slideFade', [
694683
transition('* => *', [
695-
group([ //<- 追加
684+
group([ // <- 追加
696685
query(':leave', [
697686
useAnimation(slideFadeOut)
698687
], { optional: true }),
@@ -701,9 +690,10 @@ trigger('slideFade', [
701690
useAnimation(slideFadeIn)
702691
])
703692
], { optional: true })
704-
]) //<- 追加
693+
]) // <- 追加
705694
])
706695
])
696+
// slideFade置き換えここまで
707697
```
708698

709699
これで消えつつ表示されるようになりました。

0 commit comments

Comments
 (0)