我的角度应用程序给我一个问题
console.log(JSON.stringify($rootScope.user));
正在打印出预期的用户对象,但是......
当我尝试
时console.log($rootScope.user.objectId)
或
var id = $rootScope.user.objectId;
console.log(id);
我未定义。那是什么? userId绝对是JSON.stringify
中打印出来的属性之一,所以...我很困惑。
{"username":"thinmint","email":"thinmint@thinmint.com","objectId":"FmjGa7POFH",
"createdAt":"2015-05-28T18:39:08.362Z","updatedAt":"2015-05-28T18:39:08.362Z"}
这是$rootScope.user
的示例值。
答案 0 :(得分:2)
var json = {
"username": "thinmint", "email": "thinmint@thinmint.com", "objectId": "FmjGa7POFH",
"createdAt": "2015-05-28T18:39:08.362Z", "updatedAt": "2015-05-28T18:39:08.362Z"
};
var json1 = JSON.parse(JSON.stringify(json));
alert(json1.username);