Skip to content

Commit c783181

Browse files
author
Ihor Khomiak
committed
implement base delete functionality
1 parent 19cd84a commit c783181

File tree

7 files changed

+52
-11
lines changed

7 files changed

+52
-11
lines changed
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
<ActionBar title="Details"
2-
class="action-bar"></ActionBar>
2+
class="action-bar">
3+
<ActionItem (tap)="onEdit()"
4+
ios.systemIcon="2" ios.position="right"
5+
text="Edit" android.position="popup"></ActionItem>
6+
<ActionItem (tap)="onDelete()"
7+
ios.systemIcon="16" ios.position="right"
8+
text="Delete" android.position="popup"></ActionItem>
9+
</ActionBar>
310

411
<StackLayout orientation="vertical"
512
class="page">
613
<FlexboxLayout class="m-15">
714
<Label class="h2"
815
[text]="cost.quantity"></Label>
916
</FlexboxLayout>
10-
<Label class="tag-item small-tag-item"
17+
<Label class="tag-item small-tag-item"
1118
[text]="cost.type"></Label>
1219
</StackLayout>

app/cost/cost-detail.component.js

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/cost/cost-detail.component.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Component, OnInit } from "@angular/core";
22
import { ActivatedRoute } from "@angular/router";
3+
import { RouterExtensions } from "nativescript-angular/router";
34

45
import { Cost } from "./cost";
56
import { CostService } from "./cost.service";
@@ -15,11 +16,21 @@ export class CostDetailComponent implements OnInit {
1516

1617
constructor(
1718
private costService: CostService,
18-
private route: ActivatedRoute
19+
private route: ActivatedRoute,
20+
private routerExtensions: RouterExtensions
1921
) { }
2022

2123
ngOnInit(): void {
2224
const id = +this.route.snapshot.params["id"];
2325
this.cost = this.costService.getCost(id);
2426
}
27+
28+
onEdit(){
29+
console.log('edit');
30+
}
31+
32+
onDelete(){
33+
this.costService.deleteCost(this.cost);
34+
this.routerExtensions.back();
35+
}
2536
}

app/cost/cost.service.js

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

app/cost/cost.service.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,13 @@ export class CostService {
4242
activeCosts.push(newCost);
4343
this.costsListSource.next(activeCosts);
4444
}
45+
46+
deleteCost(costForDelete: Cost) {
47+
let activeCosts = this.costsListSource.getValue();
48+
var index = activeCosts.indexOf(costForDelete);
49+
activeCosts.splice(index, 1);
50+
this.costsListSource.next(activeCosts);
51+
52+
alert(costForDelete.quantity + " removed!");
53+
}
4554
}

0 commit comments

Comments
 (0)