这是我的Angular代码。我通过AngularJS服务获得了一系列userInfo
。如何访问AngularJS中的AngularJS对象
app.controller('personalController', function ($scope, $http, $window, userInfo) {
$scope.info = userInfo.getValue();
console.log($scope.info);
//$scope.data = $scope.info;
console.log($scope.info.inf.CNIC);
}
这是我的角度服务:
app.service('userInfo', function() {
var infor = {};
this.setValue = function (info) {
infor["inf"] = info;
}
this.getValue = function (info) {
return infor;
}
})
我得到以下值:
,我在console.log($scope.info.inf.CNIC);
得到cannot read the property
错误。
它,因为异步行为的console.log被excuting什么是assinged之前$ scope.info –
我得到的值,请“这里描述”检查图像 –
这是因为'console.log'打印了对象的更新版本。 –