This article describes the Angularjs cookies read and write operation. Share to everyone for your reference, specific as follows:
Although it is easy to create and get cookies using JavaScript, ANGULARJS is encapsulated as a separate module, with the module named Ngcookies, as in the previous tutorial, First introduce angular-cookies.js:
<script type= "Text/javascript" src= "Angular-1.3.0.14/angular-cookies.js" ></script>
Then inject the Ngcookies module into our custom module:
var cookiesmod = angular.module ("Cookiesmod", [' ngcookies ']);
Here we need to inject the cookies read and write related service $cookiestore into the controller. Read and write operations through $cookiestore get and put methods .
Let's look at a complete case:
We write cookies when the page is loaded, the cookie name is person, the value is {name: "Rongbo_j", age:23}, click the button to get the cookie information and pop it in the form of a dialog box.
Next look at the effect:
Angularjs Source can click here to download the site .
I hope this article will help you to Angularjs program design.