我是Angular和cookies的新手,我有一個HTML模板,我需要在用戶第一次訪問我的應用時顯示。但是,他們下次訪問時,他們不應再看到該模板並查看默認模板。如何使用cookies? Angular-cookies
但是這兩種解決方案扔的錯誤,在第一環節==
沒有工作,下面的例子中string is not a function
如何將以下工作這段代碼進行檢查,看是否有一個cookie,如果沒有則創建的cookie 。
// Controller for Dashboard
app.controller('DashboardController', ['$scope', '$cookies', '$cookieStore', function ($scope, $cookies, $cookieStore) {
// if cookie does not exits show welcome template
// create cookie
// if cookie welcome exits show default template
$scope.welcome = $cookieStore.get('welcome');
$scope.checkCookie = function(welcome){
$scope.welcome = welcome;
$cookieStore.put('cookie', welcome);
};
// $cookieStore.put("name","my name");
// $cookieStore.get("name") = "my name";
// $cookieStore.remove("name");
}]);
使用Angular時,不需要編寫自己的模塊。只需使用ngCookies作爲接受的響應即可。 – sfuqua 2015-12-12 21:53:19