似乎没有任何关于使用AngularJS的cookie的真正明确的文档,所以我有点迷失了.
我有两个控制器,一个创建一个cookie并存储用户ID,然后我想在以后另一个控制器运行时检索该ID.我想我已经成功创建了cookie并为id存储了一个值,但是我似乎无法从第二个控制器中的cookie中取回id.当我尝试读取id时,我在控制台中收到错误:
TypeError: 'undefined' is not an object
Run Code Online (Sandbox Code Playgroud)
PS:我在Xcode工作,因为这是在iPhone的ios应用程序中.
function firstCtrl($scope, $cookieStore) {
$scope.connectToFacebook = function() {
FB.api('/me', function(response, data, status, headers, config) {
var fbid=response.id;
$cookieStore.put('id', fbid);
console.log($cookieStore.get('id')); //This correctly displays the users FB id
});
}
}
function secondCtrl($scope, $cookieStore) {
$scope.submit = function() {
console.log($cookieStore.get('id')); // This is currently displaying: TypeError: 'undefined' is not an object
};
}
Run Code Online (Sandbox Code Playgroud) 我正在寻找一个类似的解决方案,解决以前使用以下代码解决的问题:
这是我需要从上面的JSFiddle中使用的JS:
$(document).ready(function () {
$('select.hello').change(function () {
$('select.hello option').attr('disabled', false);
$('select.hello').each(function() {
var val = $(this).find('option:selected').val();
if (!val) return;
$('select.hello option').filter(function() {
return $(this).val() == val;
}).attr('disabled', 'disabled');
});
});
});
Run Code Online (Sandbox Code Playgroud)
但是,我需要在AngularJS中做到这一点,并且作为AngularJS的新手我有点难过如何将一些JS"转换"成AngularJS Seed而只需要一些指导.
基本上我有3个选择下拉列表,其中包含相同的列表(这是一个人的列表),当用户为第一个选择选择一个名称时,我需要从其他2个选择选项中删除该名称.上面的JSfiddle完美地演示了这一点,但我只需要了解如何将此代码放入AngularJS中.
提前致谢.