我正在使用此代码
从文件名last.js添加Angular Local存储 $localStorage.myData = [];
$localStorage.myData.push({
name; "faizan",
uni: "FUSSAT"
})
alert($localStorage.myData);//it is showing data as expected!!!
现在在线活动我这样做是为了访问它但不幸的是它未定义..我猜它正在制作新的$ localStorage
window.addEventListener('load', function() {
window.addEventListener('online', function updateOnlineStatus($localStorage) {
alert("online fired")//it is run when online navigatior
alert($localStorage.myData)//it is undefined..why??????????????????????????
}
}
答案 0 :(得分:0)
传递给事件处理程序的参数是一个事件对象,而不是localStorage对象https://developer.mozilla.org/en/docs/Online_and_offline_events,您必须将事件侦听器放在Angular服务或控制器中才能访问$ localStorage对象。