从 AngularJS $cookies 获取价值
Get value from AngularJS $cookies
我有一个饼干集
$cookieStore.put('lastpage', $scope.page);
我想取cookie'lastpage'的值,显示在html
<div>Last page is 'value'</div>
试试这个..
$scope.cookie = $cookieStore.get('lastpage');
<body>
<form id="form1" runat="server">
<div ng-controller="x">
Cookie Value: {{cookie}}
</div>
</form>
</body>
编辑 由于 Angular 1.4 '$cookieStore' 已弃用,因此如果使用该版本(或更高版本),则以上内容应为:
$scope.cookie = $cookies.get('lastpage');
请参阅 the docs
中的弃用警告
从 controller 中的 cookie 加载值并将其绑定到范围内。
在 js 中
// in controller
$scope.value = $cookieStore.get('lastPage');
在html
<div>Last page is '{{value}}'</div>
控制器:
app.controller("Welcome!", function($scope, $cookieStore){
$scope.value = $cookieStore.get('lastpage');
});
输入html:
<div ng-controller="Welcome!">{{value}}</div>
谢谢!
我有一个饼干集
$cookieStore.put('lastpage', $scope.page);
我想取cookie'lastpage'的值,显示在html
<div>Last page is 'value'</div>
试试这个..
$scope.cookie = $cookieStore.get('lastpage');
<body>
<form id="form1" runat="server">
<div ng-controller="x">
Cookie Value: {{cookie}}
</div>
</form>
</body>
编辑 由于 Angular 1.4 '$cookieStore' 已弃用,因此如果使用该版本(或更高版本),则以上内容应为:
$scope.cookie = $cookies.get('lastpage');
请参阅 the docs
中的弃用警告从 controller 中的 cookie 加载值并将其绑定到范围内。
在 js 中
// in controller
$scope.value = $cookieStore.get('lastPage');
在html
<div>Last page is '{{value}}'</div>
控制器:
app.controller("Welcome!", function($scope, $cookieStore){
$scope.value = $cookieStore.get('lastpage');
});
输入html:
<div ng-controller="Welcome!">{{value}}</div>
谢谢!