Skip to content

Commit af02a9f

Browse files
IsmaestroIsmael Ramos
authored andcommitted
feat(go back): add go back button with location service
1 parent 0deda48 commit af02a9f

7 files changed

Lines changed: 23 additions & 4 deletions

File tree

src/app/heroes/hero-detail/hero-detail.component.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ <h1 class="section-title">{{'heroDetail' | translate}}</h1>
2525
</mat-card>
2626
</ng-container>
2727
</div>
28+
29+
<button mat-raised-button type="button" (click)="goBack()">
30+
{{'goBack' | translate | uppercase}}
31+
</button>

src/app/heroes/hero-detail/hero-detail.component.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@
22
width: 65%;
33
margin: 0 auto;
44
margin-top: 2em;
5+
}
6+
7+
button {
8+
margin: 2rem auto;
9+
display: block;
510
}

src/app/heroes/hero-detail/hero-detail.component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {Component, OnInit} from '@angular/core';
22
import {Hero} from '../shared/hero.model';
33
import {HeroService} from '../shared/hero.service';
44
import {ActivatedRoute} from '@angular/router';
5+
import {Location} from '@angular/common';
56

67
@Component({
78
selector: 'app-hero-detail',
@@ -15,6 +16,7 @@ export class HeroDetailComponent implements OnInit {
1516
canVote: boolean;
1617

1718
constructor(private heroService: HeroService,
19+
private location: Location,
1820
private activatedRoute: ActivatedRoute) {
1921
}
2022

@@ -35,4 +37,8 @@ export class HeroDetailComponent implements OnInit {
3537
});
3638
});
3739
}
40+
41+
goBack(): void {
42+
this.location.back();
43+
}
3844
}

src/assets/i18n/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@
4848
"mayTheForce": "May the force be with you",
4949
"updateBrowser": "You are using an old browser, please update it and reload the page.",
5050
"firstTwoHeroesById": "Heroes (1-2)",
51-
"offlineMessage": "Without connection we can not load anything!"
51+
"offlineMessage": "Without connection we can not load anything!",
52+
"goBack": "Go back"
5253
}

src/assets/i18n/es.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@
4848
"mayTheForce": "Que la fuerza te acompañe",
4949
"updateBrowser": "Estas usando un navegador antiguo, por favor actualiza la versión y recarga la página.",
5050
"firstTwoHeroesById": "Heroes (1-2)",
51-
"offlineMessage": "Sin conexión no podemos cargar nada!"
51+
"offlineMessage": "Sin conexión no podemos cargar nada!",
52+
"goBack": "Volver"
5253
}

src/assets/i18n/pt-br.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@
4848
"mayTheForce": "Que a força te acompanhe",
4949
"updateBrowser": "Você está usando um navegador antigo, atualize a versão e recarregue a página.",
5050
"firstTwoHeroesById": "Heróis (1-2)",
51-
"offlineMessage": "Sem conexão não podemos carregar nada!"
51+
"offlineMessage": "Sem conexão não podemos carregar nada!",
52+
"goBack": "Voltar"
5253
}

src/assets/i18n/zh.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@
4848
"mayTheForce": "愿力量与你同在",
4949
"updateBrowser": "您正在使用一个旧版本浏览器,请更新它并重新加载页面。",
5050
"firstTwoHeroesById": "英雄 (1-2)",
51-
"offlineMessage": "沒有連接,我們無法加載任何東西!"
51+
"offlineMessage": "沒有連接,我們無法加載任何東西!",
52+
"goBack": "回來"
5253
}

0 commit comments

Comments
 (0)