我在我当前的项目中使用 AngularJS,我正在尝试实现一个功能来检测浏览器中是否禁用了 cookie。我尝试使用 AngularJS 模块“ngCookies”来解决这个问题。此功能的主要思想是创建一些 cookie,然后检查此 cookie 是否已创建(并且可用),如果没有则显示消息。但它没有奏效。
控制器:
someProject.controller('CookieCtrl', ['$scope', '$cookieStore', function($scope, $cookieStore) {
$scope.areCookiesEnabled = false;
$cookieStore.put("TestCookie", "TestCookieText");
$scope.cookieValue = $cookieStore.get("TestCookie");
if ($scope.cookieValue) {
$cookieStore.remove("TestCookie");
$scope.areCookiesEnabled = true;
}
}]);
看法:
<div class="main" data-ng-controller="CookieCtrl">
<div class="warning_message" data-ng-show="!areCookiesEnabled">
<span data-ng-bind="areCookiesEnabled"></span>
</div>
</div>
谁能告诉我我的错误在哪里?