简体   繁体   中英

Is it possible to store session in simple JavaScript function and then access that session attribute in angularjs?

我正在尝试将选定的单选按钮的值存储在JavaScript的会话存储中。后来我希望将该值用于angularjs函数。是否可以。如果是,请帮助我

Yes you can make use of localStorage of the browser

window.localStorage - stores data with no expiration date
code.sessionStorage - stores data for one session (data is lost when the tab is closed)

// Store
localStorage.setItem("lastname", "Smith");
// Retrieve
document.getElementById("result").innerHTML = localStorage.getItem("lastname");

In AngularJS, you can make use of Angular-local-storage

JSFiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM