Angularjs 使用ngStorage我可以使用var作为存储的名称/密钥吗?
我只是用ngStorge把脚弄湿了,所以这可能很简单 我正在使用 以下是他们的读/写演示:Angularjs 使用ngStorage我可以使用var作为存储的名称/密钥吗?,angularjs,local-storage,ng-storage,Angularjs,Local Storage,Ng Storage,我只是用ngStorge把脚弄湿了,所以这可能很简单 我正在使用 以下是他们的读/写演示: <!DOCTYPE html> <html ng-app="app"> <head> <script data-require="angular.js@1.1.5" data-semver="1.1.5" src="http://code.angularjs.org/1.1.5/angular.min.js"></script>
<!DOCTYPE html>
<html ng-app="app">
<head>
<script data-require="angular.js@1.1.5" data-semver="1.1.5" src="http://code.angularjs.org/1.1.5/angular.min.js"></script>
<script src="https://rawgithub.com/gsklee/ngStorage/master/ngStorage.js"></script>
<script>
angular.module('app', [
'ngStorage'
]).
controller('Ctrl', function(
$scope,
$localStorage
){
$scope.$storage = $localStorage.$default({
x: 42
});
});
</script>
</head>
<body ng-controller="Ctrl">
<button ng-click="$storage.x = $storage.x + 1">{{$storage.x}}</button> + <button ng-click="$storage.y = $storage.y + 1">{{$storage.y}}</button> = {{$storage.x + $storage.y}}
</body>
</html>
并使用testx代替.x
<button ng-click="$storage.x = $storage.x + 1">{{$storage.x}}</button>
{{$storage.x}
提前感谢。如果我理解正确,您可以使用括号符号,如下面的代码:
<button ng-click="$storage[ testx ] = $storage[ testx ] + 1">{{$storage[ testx ]}}</button>
{{$storage[testx]}
如果我理解正确,您可以使用括号符号,如下面的代码:
<button ng-click="$storage[ testx ] = $storage[ testx ] + 1">{{$storage[ testx ]}}</button>
{{$storage[testx]}
如果我理解正确,您可以使用括号符号,如下面的代码:
<button ng-click="$storage[ testx ] = $storage[ testx ] + 1">{{$storage[ testx ]}}</button>
{{$storage[testx]}
如果我理解正确,您可以使用括号符号,如下面的代码:
<button ng-click="$storage[ testx ] = $storage[ testx ] + 1">{{$storage[ testx ]}}</button>
{{$storage[testx]}
如果将变量设置为键值会怎么样?或者这不是您想要的?如果您将变量设置为键值呢?或者这不是您想要的?如果您将变量设置为键值呢?或者这不是您想要的?如果您将变量设置为键值呢?或者这不是你想要的?