Skip to content

Commit 0015b78

Browse files
committed
Dinamic show post working
1 parent 46680ae commit 0015b78

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

angular/wallypop/.idea/workspace.xml

Lines changed: 1 addition & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

angular/wallypop/src/app/app.routing.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const appRoutes = [
1919
{ path: 'categoryList', component: CategoryListComponent},
2020
{ path: 'commercial', component: CommercialComponent },
2121
{ path: 'post', component: PostComponent },
22+
{ path: 'post/:id', component: PostComponent },
2223
{ path: '**', component: NotFoundComponent}
2324
];
2425

angular/wallypop/src/app/components/articles/post.component.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {Category} from '../../models/category.model';
66
import {CategoryService} from '../../services/category.service';
77
import {User} from '../../models/user.model';
88
import {Observable} from 'rxjs';
9+
import {ActivatedRoute, Router} from '@angular/router';
910

1011
@Component({
1112
selector: 'post',
@@ -15,12 +16,21 @@ export class PostComponent implements OnInit {
1516
article: Article;
1617
user: User;
1718
categories: Category[];
18-
constructor(private articleService: ArticleService, private categoryService: CategoryService, public loginService: LoginService) {
19+
idArticle: number;
20+
// tslint:disable-next-line:max-line-length
21+
constructor(private articleService: ArticleService, private categoryService: CategoryService, public loginService: LoginService, private routing: ActivatedRoute, private router: Router) {
22+
this.idArticle = -1;
1923
}
2024

2125
ngOnInit(): void {
2226
this.getCategories();
23-
this.getArticle(3);
27+
this.idArticle = this.routing.snapshot.params.id;
28+
if (this.idArticle !== -1) {
29+
this.getArticle(this.idArticle);
30+
/* if (this.article === undefined) {
31+
this.router.navigate(['commercial']);
32+
} */
33+
}
2434
}
2535

2636
getCategories(): void {

0 commit comments

Comments
 (0)