我正在使用PHP在離子中創建登錄應用程序,我有一個登錄功能,它工作良好,但我需要能夠將某些值存儲到本地存儲以備後用。使用angularjs從json獲取值
這裏是我的代碼示例:
$scope.login = function() {
Login.login($scope.login).then(function (data) {
if (Object.keys(data.data).length === 1) {
var datao = angular.toJson(data);
$scope.profile = datao;
$scope.email = $scope.profile.email;
$scope.username = $scope.profile.username;
console.log(data);
console.log($scope.profile);
// $state.go('dashboard');
}
....
});
....
});
$scope.profile
顯示以下內容:
[Log]
{
"data": [{
"id": "5",
"username": "ozombo",
"reputation": "ceo",
"activate": "8425",
"followercount": "3",
"praycount": "0",
"donetour": "0",
"fb_id": "0",
"fullname": "Adebambo Oyelaja",
"church": "RCCG ",
"photo": "1417451697.jpg",
"twtr_id": "0",
"screen_name": "",
"email": "[email protected]",
"bio": "Geek, Father, Husband",
"country": "Nigeria",
"state": "Lagos",
"followscount": "0",
"account": "",
"password": "5cf1bc1b9a2ada1ae9e29079aae1aefa",
"signup_date": "1413305984",
"signupdevice": "web",
"keycode": "5fc868f0767b0c164341a9e8e35edbe4",
"last_login": "1436519269",
"city": "Palmgroove",
"campaign": "",
"bday": "29-09-1988",
"gender": "Male",
"approved": "0",
"donewelcome": "0",
"phonenumber": "07017993683",
"secure": "private",
"churchid": "1",
"views": "68",
"marital": "Married"
}],
"status": 200,
"config": {
"method": "GET",
"transformRequest": [null],
"transformResponse": [null],
"url": "http://localhost:8888/opb/api/[email protected]&pass=oyelaja",
"headers": {
"Accept": "application/json, text/plain, /"
}
},
"statusText": "OK"
}
我將如何得到例如
var email = $ scope.profile.data.email不工作...錯誤:undefined不是一個對象(評估'$ scope.profile.data.email') –
如果$ scope.profile記錄了你在帖子中顯示你可以訪問像我說的 –
是的我的日誌顯示我發佈的內容,但是當我這樣做時: $ scope.profile = datao; console.log($ scope.profile.data.email); 我得到錯誤:undefined不是一個對象(評估'$ scope.profile.data.email') –