如何使用JavaScript / Angular.js

时间:2015-09-25 10:57:26

标签: javascript angularjs

我有一个产生低于输出的数组对象。

console.log('response',response);

response [{"id":"2","name":"subhra","pass":"12345","email":"subh@gmail.com"}]

在这里,我需要使用JavaScript的所有个人值(email,id,pass,name)。请帮我解决此问题。

2 个答案:

答案 0 :(得分:1)

Updated link

var data=[{"id":"2","name":"subhra","pass":"12345","email":"subh@gmail.com"}];
console.log('response',data);

    console.log('response',data[0].id); //2
    console.log('response',data[0].name); //subhra
    console.log('response',data[0].pass); //12345
    console.log('response',data[0].email); //subh@gmail.com

答案 1 :(得分:0)

您可以使用angular.forEach

工作Plunker

<强>控制器

$scope.response = [{"id":"2","name":"subhra","pass":"12345","email":"subh@gmail.com"}]

angular.forEach($scope.response, function(item){
    $scope.Id = item.id; // id is in $scope.Id
    $scope.Name = item.name; // name is in $scope.Name
    $scope.Email = item.email; // email is in $scope.Email
    scope.Pass = item.pass;   // pass is in $scope.Pass
});

<强> HTML

<body ng-controller="MainCtrl">
    <p> ID : {{Id}}</p>
    <p> Name : {{Name}}</p>
    <p> Pass : {{Pass}}</p>
    <p> email : {{Email}}</p>
</body>