File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55 "angular-cli" : {},
66 "scripts" : {
77 "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" ,
99 "ng" : " ng serve --proxy-config proxy.conf.json" ,
1010 "tslint" : " tslint \" src/**/*.ts\" ; exit 0" ,
1111 "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>
4141 < i class ="fa fa-pencil-square-o " aria-hidden ="true "> </ i >
4242 </ button >
4343 < button class ="btn btn-danger "
44- (click) ="remove (hero); $event.stopPropagation( ) ">
44+ (click) ="showRemoveModal (hero) ">
4545 < i class ="fa fa-times " aria-hidden ="true "> </ i >
4646 </ button >
4747 </ 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 >
4869 </ li >
4970 </ ul >
5071 </ div >
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import {IAppConfig} from '../../config/iapp.config';
66
77import { Hero } from '../shared/hero.model' ;
88import { HeroService } from '../shared/hero.service' ;
9+ declare const $ :any ;
910
1011@Component ( {
1112 selector : 'toh-hero-list' ,
@@ -16,6 +17,7 @@ import {HeroService} from '../shared/hero.service';
1617export class HeroListComponent implements OnInit {
1718 heroes : Hero [ ] ;
1819 selectedHero : Hero ;
20+ heroToRemove : Hero ;
1921 color : string ;
2022 createNewHero : boolean ;
2123
@@ -40,14 +42,20 @@ export class HeroListComponent implements OnInit {
4042 this . router . navigate ( [ `/${ this . appConfig . routes . heroes } /` , this . selectedHero . id ] ) ;
4143 }
4244
43- remove ( hero : Hero ) : void {
45+ remove ( ) : void {
46+ $ ( '#askForRemove' ) . modal ( 'hide' ) ;
4447 this . heroService
45- . remove ( hero . id )
48+ . remove ( this . heroToRemove . id )
4649 . 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 ) {
4952 this . selectedHero = null ;
5053 }
5154 } ) ;
5255 }
56+
57+ showRemoveModal ( hero : Hero ) : void {
58+ this . heroToRemove = hero ;
59+ $ ( '#askForRemove' ) . modal ( 'show' ) ;
60+ }
5361}
You can’t perform that action at this time.
0 commit comments