-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathitem.service.ts
More file actions
75 lines (64 loc) · 1.37 KB
/
item.service.ts
File metadata and controls
75 lines (64 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class ItemService {
items: Array<any> = [
{
'id': "1",
'title': "Example 1",
'description': 'description 1'
},
{
'id': "2",
'title': "Example 2",
'description': 'description 2'
},
{
'id': "3",
'title': "Example 3",
'description': 'description 3'
},
{
'id': "4",
'title': "Example 4",
'description': 'description 4'
},
{
'id': "6",
'title': "Example 5",
'description': 'This is example 5'
},
{
'id': "5",
'title': "Need a more complex app?",
'description': 'Check the Ionic 4 Full Starter App.'
}
]
constructor() { }
createItem(title, description){
let randomId = Math.random().toString(36).substr(2, 5);
this.items.push({
'id': randomId,
'title': title,
'description': description
});
}
getItems(){
return this.items;
}
getItemById(id){
return this.items.filter(item => item.id === id);
}
updateItem(newValues){
let itemIndex = this.items.findIndex(item => item.id == newValues.id);
this.items[itemIndex] = newValues;
}
deleteItem(value){
this.removeItemFromArr(this.items,value)
}
removeItemFromArr(arr,item){
var i = arr.indexOf(item);
arr.splice(i,1);
}
}