Skip to content

Commit 39ae3ab

Browse files
committed
ステップ④ タスク一覧を別ページで作成する
1 parent 50cbf0e commit 39ae3ab

File tree

8 files changed

+108
-3
lines changed

8 files changed

+108
-3
lines changed

src/app/app-routing.module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const routes: Routes = [
1414
{
1515
path: 'list',
1616
loadChildren: () => import('./list/list.module').then(m => m.ListPageModule)
17+
},
18+
{
19+
path: 'tasks',
20+
loadChildren: () => import('./task-list/task-list.module').then( m => m.TaskListPageModule)
1721
}
1822
];
1923

src/app/app.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import { StatusBar } from '@ionic-native/status-bar/ngx';
1212
export class AppComponent {
1313
public appPages = [
1414
{
15-
title: 'Home',
15+
title: 'タスク登録',
1616
url: '/home',
1717
icon: 'home'
1818
},
1919
{
20-
title: 'List',
21-
url: '/list',
20+
title: 'タスク一覧',
21+
url: '/tasks',
2222
icon: 'list'
2323
}
2424
];
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { NgModule } from '@angular/core';
2+
import { Routes, RouterModule } from '@angular/router';
3+
4+
import { TaskListPage } from './task-list.page';
5+
6+
const routes: Routes = [
7+
{
8+
path: '',
9+
component: TaskListPage
10+
}
11+
];
12+
13+
@NgModule({
14+
imports: [RouterModule.forChild(routes)],
15+
exports: [RouterModule],
16+
})
17+
export class TaskListPageRoutingModule {}

src/app/task-list/task-list.module.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
import { FormsModule } from '@angular/forms';
4+
5+
import { IonicModule } from '@ionic/angular';
6+
7+
import { TaskListPageRoutingModule } from './task-list-routing.module';
8+
9+
import { TaskListPage } from './task-list.page';
10+
11+
@NgModule({
12+
imports: [
13+
CommonModule,
14+
FormsModule,
15+
IonicModule,
16+
TaskListPageRoutingModule
17+
],
18+
declarations: [TaskListPage]
19+
})
20+
export class TaskListPageModule {}

src/app/task-list/task-list.page.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<ion-header>
2+
<ion-toolbar>
3+
<ion-buttons slot="start">
4+
<ion-menu-button></ion-menu-button>
5+
</ion-buttons>
6+
<ion-title>タスク一覧</ion-title>
7+
</ion-toolbar>
8+
</ion-header>
9+
10+
<ion-content>
11+
<ion-list>
12+
<ion-item *ngFor="let t of tasks">
13+
<ion-label>{{t.name}}</ion-label>
14+
</ion-item>
15+
</ion-list>
16+
</ion-content>

src/app/task-list/task-list.page.scss

Whitespace-only changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
import { IonicModule } from '@ionic/angular';
3+
4+
import { TaskListPage } from './task-list.page';
5+
6+
describe('TaskListPage', () => {
7+
let component: TaskListPage;
8+
let fixture: ComponentFixture<TaskListPage>;
9+
10+
beforeEach(async(() => {
11+
TestBed.configureTestingModule({
12+
declarations: [ TaskListPage ],
13+
imports: [IonicModule.forRoot()]
14+
}).compileComponents();
15+
16+
fixture = TestBed.createComponent(TaskListPage);
17+
component = fixture.componentInstance;
18+
fixture.detectChanges();
19+
}));
20+
21+
it('should create', () => {
22+
expect(component).toBeTruthy();
23+
});
24+
});

src/app/task-list/task-list.page.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-task-list',
5+
templateUrl: './task-list.page.html',
6+
styleUrls: ['./task-list.page.scss'],
7+
})
8+
export class TaskListPage implements OnInit {
9+
tasks: { name: string }[] = [
10+
{ name: 'タスク1' },
11+
{ name: 'タスク2' },
12+
];
13+
constructor() { }
14+
15+
ngOnInit() {
16+
}
17+
18+
ionViewWillEnter() {
19+
if ('tasks' in localStorage) {
20+
this.tasks = JSON.parse(localStorage.tasks);
21+
}
22+
}
23+
24+
}

0 commit comments

Comments
 (0)