Angularjs Summary (eight) $ cookie and $rootscope

Source: Internet
Author: User


AngularJS provides good $cookie and $cookieStore APIs to handle cookies.
Both services are able to play HTML5 cookies well, and when the HTML5 API is available the browser chooses to use the API provided by HTML5 and, if not available, chooses document.cookies by default. Either way, you can choose to use phase
The same API to work on.
You can now manipulate cookies using the put, get, and remove methods, $cookieStore can store objects directly into cookies, which are automatically serialized and deserialized using Angularjs Tojson/fromjson
$cookieStore. Put ("name", "My Name");
$cookieStore. Get ("name") = = "My Name";
$cookieStore. Remove ("name");
$cookieStore. Put ("Persion", {
Name: "My Name",
Age:18
});
$scope. person = $cookieStore. Get ("persion");

Using cookies
$cookies. Put (' SESSIONSZWC ', sessionobject);
$cookies. Get ("SESSIONSZWC");
$cookies. Remove (' SESSIONSZWC ');
$cookies. myfavorite = ' oatmeal haha ';

Scope is a bridge between HTML and a single controller, and data binding depends on him.
Rootscope is the bridge of scope in each controller. Values defined with Rootscope can be used in each controller

Angularjs Summary (eight) $ cookie and $rootscope

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.