我正在使用AngularJS,根据其文档,最好使用ngCookies处理cookies。 我使用以下结构添加ngCookie:
- add angular.js and angular-cookies.min.js to my index.html
inject ngCookie to to my app using this code :
var app = angular.module('test', ['ngRoute','ngAnimate','ngFileUpload','ngSanitize','ngCookies']);
and now i inject ng-cookie to my own service :
app.service("transactionService", ["$cookie", "$http","sessionStorageService", function($cookie, $http, sessionStorageService){ $cookies.put("unique_code",123456); console.log(sessionStorageService.getCurrentUser().sessionid); console.log($cookies.get("unique_code")); return; } ]);