public todos: {
id: number,
title: string,
done: boolean
}[] = JSON.parse(window.localStorage.getItem('todos') || '[]')
ngDoCheck(){
window.localStorage.setItem('todos', JSON.stringify(this.todos))
}
-
JSON.parse() 将字符串转化为JSON数组
-
JSON.stringify() 将JSON数组转化为字符串