Answer the question
In order to leave comments, you need to log in
How to write an array of objects from JSON / Angular2 to a variable?
In an Angular2 service, I access an array of objects stored in a separate json file.
export class CartService {
constructor(private http: Http){ }
getCartItems() {
return this.http.get('../cart.json')
.map(
(res) => res.json()
);
}
}
[
{
"id":"id-1",
"title": "Title-1",
"image": "https://bla.bla/bla/01.jpg",
"slider": "https://bla.bla/bla//slider01.jpg",
"description": "Description-1",
"price": 67887,
"quantity": " "
},
{
"id":"id-2",
"title": "Title-2",
"image": "https://bla.bla/bla/02.jpg",
"slider": "https://bla.bla/bla//slider02.jpg",
"description": "Description-2",
"price": 69007,
"quantity": " "
},
...,
...,
...
]
Answer the question
In order to leave comments, you need to log in
As an option, make a storage service and store this array there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question