File tree 2 files changed +63
-2
lines changed
2 files changed +63
-2
lines changed Original file line number Diff line number Diff line change 9
9
10
10
< ion-content >
11
11
< ion-list >
12
- < ion-item *ngFor ="let t of tasks ">
12
+ < ion-item *ngFor ="let t of tasks; let i = index " [button] ="true "
13
+ (click) ="changeTask(i) ">
13
14
< ion-label > {{t.name}}</ ion-label >
14
15
</ ion-item >
15
16
</ ion-list >
Original file line number Diff line number Diff line change 1
1
import { Component , OnInit } from '@angular/core' ;
2
+ import { ActionSheetController , AlertController } from '@ionic/angular' ;
2
3
3
4
@Component ( {
4
5
selector : 'app-task-list' ,
@@ -10,7 +11,10 @@ export class TaskListPage implements OnInit {
10
11
{ name : 'タスク1' } ,
11
12
{ name : 'タスク2' } ,
12
13
] ;
13
- constructor ( ) { }
14
+ constructor (
15
+ public actionSheetController : ActionSheetController ,
16
+ public alertController : AlertController ,
17
+ ) { }
14
18
15
19
ngOnInit ( ) {
16
20
}
@@ -21,4 +25,60 @@ export class TaskListPage implements OnInit {
21
25
}
22
26
}
23
27
28
+ async changeTask ( index : number ) {
29
+ const actionSheet = await this . actionSheetController . create ( {
30
+ header : 'タスクの変更' ,
31
+ buttons : [
32
+ {
33
+ text : '削除' ,
34
+ role : 'destructive' ,
35
+ icon : 'trash' ,
36
+ handler : ( ) => {
37
+ this . tasks . splice ( index , 1 ) ;
38
+ localStorage . tasks = JSON . stringify ( this . tasks ) ;
39
+ }
40
+ } , {
41
+ text : '変更' ,
42
+ icon : 'create' ,
43
+ handler : ( ) => {
44
+ this . _renameTask ( index ) ;
45
+ }
46
+ } , {
47
+ text : '閉じる' ,
48
+ icon : 'close' ,
49
+ role : 'cancel' ,
50
+ handler : ( ) => {
51
+ console . log ( 'Cancel clicked' ) ;
52
+ }
53
+ } ,
54
+ ]
55
+ } ) ;
56
+ actionSheet . present ( ) ;
57
+ }
58
+
59
+ async _renameTask ( index : number ) {
60
+ const prompt = await this . alertController . create ( {
61
+ header : '変更後のタスク' ,
62
+ inputs : [
63
+ {
64
+ name : 'task' ,
65
+ placeholder : 'タスク' ,
66
+ value : this . tasks [ index ] . name
67
+ } ,
68
+ ] ,
69
+ buttons : [
70
+ {
71
+ text : '閉じる'
72
+ } ,
73
+ {
74
+ text : '保存' ,
75
+ handler : data => {
76
+ this . tasks [ index ] = { name : data . task } ;
77
+ localStorage . tasks = JSON . stringify ( this . tasks ) ;
78
+ }
79
+ }
80
+ ]
81
+ } ) ;
82
+ prompt . present ( ) ;
83
+ }
24
84
}
You can’t perform that action at this time.
0 commit comments