Skip to content

Commit a0e3b89

Browse files
committed
Remove category working
1 parent fb41f79 commit a0e3b89

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

angular/wallypop/src/app/components/category/categoryList.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
<div class="full-width post-info">
8282
<a class="full-width post-info-price" href="/commercial/{{category.id_CATEGORY}}">{{category.title}}</a>
8383
<span class="post-info-zone">{{category.description}}</span>
84-
<a class="post-info-date" href="/categoryList/{{category.id_CATEGORY}}/delete">x</a>
84+
<a class="post-info-date" (click)="removeCategory(category)" href="/categoryList">x</a>
8585

8686
</div>
8787
</div>

angular/wallypop/src/app/components/category/categoryList.component.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {Component, OnInit} from '@angular/core';
2+
import { Router } from '@angular/router';
23
import { Category } from 'src/app/models/category.model';
34
import {CategoryService} from '../../services/category.service';
45
import {LoginService} from '../../services/login.service';
@@ -11,7 +12,7 @@ export class CategoryListComponent implements OnInit{
1112

1213
categories: Category[];
1314

14-
constructor(public categoryService: CategoryService, public loginService: LoginService) {
15+
constructor(public categoryService: CategoryService, public loginService: LoginService, private router: Router) {
1516
}
1617
ngOnInit(): void {
1718
this.categoryService.getCategories().subscribe(
@@ -25,4 +26,14 @@ export class CategoryListComponent implements OnInit{
2526
this.categoryService.addCategory(title,description,icon);
2627
}
2728

29+
removeCategory(removeCategorySelected: Category): void {
30+
const okResponse = window.confirm('Do you want to remove this category?');
31+
if (okResponse) {
32+
this.categoryService.deleteCategory(removeCategorySelected).subscribe(
33+
_ => this.router.navigate(['/category']),
34+
error => console.error(error)
35+
);
36+
}
37+
}
38+
2839
}

0 commit comments

Comments
 (0)