JavaLearner1 JavaLearner1 - 4 months ago 11
AngularJS Question

AngularJS Cookies - Cookies saved in Browser but not displaying

I have injected the cookies and i am saving the value in cookies like this,

$cookies.name = "Alfred";
console.log("cookie " +$cookies.name);


and in HTML i display

{{name}}


the cookies are getting saved and displayed in console, But in HTML it is not getting displayed. I have checked the chrome browser too, the cookies are saved in localhost..

Answer

you need to have a scope variable to display it

$cookies.name = "Alfred";
$scope.cookiname = $cookies.name ;

In HTML

<div>Name: {{cookiname}}</div>

Here is the working App