0

I want to access cookie value in html, I need to check one condition saying ng-if='cookievalue==1' ....so that i can hide and show the content

2 Answers 2

5

To get hold of the cookie in HTML, you first need to store its reference /value in angularJS controller scope. Only when you associate with $scope you can access it in html

Sign up to request clarification or add additional context in comments.

Comments

3

Manasi is right, you have to have a controller in order to access values from HTML.

Your HTML:

<div ng-if="cookievalue==1"> ... </div>

Your controller:

.controller('ExampleController', ['$scope', '$cookies', function($scope, $cookies) {

  $scope.cookievalue = $cookies.get('mycookie');

}]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.