所以我试图同时使用角度 cookie 和本地存储,我不确定为什么 cookie 会以它们的方式工作。基本上,console.log(theInternet) 部分在日志中输入它是未定义的,当明确输入时,它的值是 12。
<body ng-app="app" ng-controller="Ctrl">
<div ng-controller="internet-test-controller">
<p>hi</p>
</br>
</br>
<button ng-click="$storage.counter = $storage.counter + 1">{{$storage.counter}}</button>
<div ng-click="$storage.money = $storage.money + 1">{{$storage.money}}</div>
</div>
</body>
<script>
var the_app = angular.module('app', ['ngStorage', 'ngCookies'])
the_app.controller('Ctrl', function ($scope, $localStorage, $cookies){
$scope.$storage = $localStorage.$default({
counter: 1,
money: $cookies.get('123abc')
});
});
the_app.controller('internet-test-controller', ['$cookies', function($cookies) {
var theInternet = $cookies.get('123abc');
$cookies.put('123abc', 12);
console.log(theInternet);
}]);
</script>