티스토리 뷰
반응형
Angular를 사용하면서 JSON으로 받은 데이터를 localStorage에 담을일이 생겼다.
처음에는 어떻게 해야하나 싶었는데 결국에는 JSON을 String으로 변환시킨
후에 나중에 사용할 때 파싱을 통해 JSON 데이터로 다시 변환시키면 된다.
var testObject = { 'one': 1, 'two': 2, 'three': 3 };
// Put the object into storage , String 으로 데이터를 저장
localStorage.setItem('testObject', JSON.stringify(testObject));
// Retrieve the object from storage, 담겨져 있는 데이터 가져오기
const retrievedObject = localStorage.getItem('testObject');
// Object로 데이터를 파싱
console.log('retrievedObject: ', JSON.parse(retrievedObject));
// 다른 객체에 옮기기
JSON.parse(retrievedObject)).forEach( vo => {
const req = new NumVO();
req.one = vo.one
req.two = vo.two
req.three = vo.three
});
이런식으로 사용하면 된다.
반응형
'FrontEnd > Angular' 카테고리의 다른 글
Textarea String으로 저장 (0) | 2018.08.02 |
---|---|
RxJS (0) | 2018.07.31 |
RouterEvent의 Navigation Detect (0) | 2018.07.18 |
Angular 쿼리파람 (0) | 2018.07.16 |
Angular Router Guard + parameter (0) | 2018.07.13 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- JPA
- data component
- data table component
- data component module
- Spring Boot
- localStorage
- Java
- React-router
- angular router
- Python
- Angular
- mobx
- JSON
- python3
- Spring
- data gird component
- JavaScript
- CSS
- jQuery
- react
- https://www.tistory.com/auth/logout/
- data grid component
- facebook login
- 파이썬
- Router
- 페이스북 로그인
- Redux
- 파이썬3
- MySQL
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함