File tree Expand file tree Collapse file tree 5 files changed +35
-6
lines changed Expand file tree Collapse file tree 5 files changed +35
-6
lines changed Original file line number Diff line number Diff line change 5
5
"angular-cli" : {},
6
6
"scripts" : {
7
7
"start" : " npm run server | npm run ng" ,
8
- "server" : " json-server --port 3000 --watch src/ server/db.json --routes src/ server/routes.json" ,
8
+ "server" : " json-server --port 3000 --watch server/db.json --routes server/routes.json" ,
9
9
"ng" : " ng serve --proxy-config proxy.conf.json" ,
10
10
"tslint" : " tslint \" src/**/*.ts\" ; exit 0" ,
11
11
"test" : " ng test" ,
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change @@ -41,10 +41,31 @@ <h3>Pick a highlight color</h3>
41
41
< i class ="fa fa-pencil-square-o " aria-hidden ="true "> </ i >
42
42
</ button >
43
43
< button class ="btn btn-danger "
44
- (click) ="remove (hero); $event.stopPropagation( ) ">
44
+ (click) ="showRemoveModal (hero) ">
45
45
< i class ="fa fa-times " aria-hidden ="true "> </ i >
46
46
</ button >
47
47
</ div >
48
+ < div class ="modal fade " id ="askForRemove " tabindex ="-1 " role ="dialog " aria-labelledby ="exampleModalLabel " aria-hidden ="true ">
49
+ < div class ="modal-dialog " role ="document ">
50
+ < div class ="modal-content ">
51
+ < div class ="modal-header ">
52
+ < h5 class ="modal-title " id ="exampleModalLabel "> Alert</ h5 >
53
+ < button type ="button " class ="close " data-dismiss ="modal " aria-label ="Close ">
54
+ < span aria-hidden ="true "> ×</ span >
55
+ </ button >
56
+ </ div >
57
+ < div class ="modal-body ">
58
+ Do you want to remove the hero?
59
+ </ div >
60
+ < div class ="modal-footer ">
61
+ < button type ="button " class ="btn btn-secondary " data-dismiss ="modal "> Cancel</ button >
62
+ < button type ="button " class ="btn btn-primary " (click) ="remove() ">
63
+ Remove hero
64
+ </ button >
65
+ </ div >
66
+ </ div >
67
+ </ div >
68
+ </ div >
48
69
</ li >
49
70
</ ul >
50
71
</ div >
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import {IAppConfig} from '../../config/iapp.config';
6
6
7
7
import { Hero } from '../shared/hero.model' ;
8
8
import { HeroService } from '../shared/hero.service' ;
9
+ declare const $ :any ;
9
10
10
11
@Component ( {
11
12
selector : 'toh-hero-list' ,
@@ -16,6 +17,7 @@ import {HeroService} from '../shared/hero.service';
16
17
export class HeroListComponent implements OnInit {
17
18
heroes : Hero [ ] ;
18
19
selectedHero : Hero ;
20
+ heroToRemove : Hero ;
19
21
color : string ;
20
22
createNewHero : boolean ;
21
23
@@ -40,14 +42,20 @@ export class HeroListComponent implements OnInit {
40
42
this . router . navigate ( [ `/${ this . appConfig . routes . heroes } /` , this . selectedHero . id ] ) ;
41
43
}
42
44
43
- remove ( hero : Hero ) : void {
45
+ remove ( ) : void {
46
+ $ ( '#askForRemove' ) . modal ( 'hide' ) ;
44
47
this . heroService
45
- . remove ( hero . id )
48
+ . remove ( this . heroToRemove . id )
46
49
. then ( ( ) => {
47
- this . heroes = this . heroes . filter ( h => h !== hero ) ;
48
- if ( this . selectedHero === hero ) {
50
+ this . heroes = this . heroes . filter ( h => h !== this . heroToRemove ) ;
51
+ if ( this . selectedHero === this . heroToRemove ) {
49
52
this . selectedHero = null ;
50
53
}
51
54
} ) ;
52
55
}
56
+
57
+ showRemoveModal ( hero : Hero ) : void {
58
+ this . heroToRemove = hero ;
59
+ $ ( '#askForRemove' ) . modal ( 'show' ) ;
60
+ }
53
61
}
You can’t perform that action at this time.
0 commit comments