hussain
hussain

Reputation: 7083

How can i access object inside array of object?

I have control Owners json object so i am trying to get worker from it , How can i assign worker json object to $scope.controlOwnerObj.worker ?

ctrl.js

if ($state.is('app.editControl')) {
          angular.forEach($scope.controlDTO.controlOwners,function(owner){
            $scope.selectedOwners = owner 
          })
         // $scope.selectedOwners = $scope.controlDTO.controlOwners[0].worker;
//        $scope.controlDTO.controlOwners[0].worker.fullName;
          console.log('EDIT CONTROL OWNERS DATA', $scope.selectedOwners);
        }

json.js

"controlOwners": [{
    "worker": {
        "workerKey": -1093,
        "sourceFeed": null,
        "statusLookUpCode": null,
        "externalId": null,
        "createdUserText": null,
        "createdTimestamp": null,
        "modifiedUserText": null,
        "modifiedTimestamp": null,
        "stdId": "ZK84T1N",
        "ccId": null,
        "empClasId": null,
        "deptId": null,
        "fullName": "Rajasekaran, Shanmuga",
    }
}],

Upvotes: 0

Views: 318

Answers (2)

Osama Saeed
Osama Saeed

Reputation: 149

Try to use like this

$scope.controlOwners[0].worker.fullName = 'Rajasekaran, Shanmuga';

Upvotes: 0

tymeJV
tymeJV

Reputation: 104775

Specify the array index you want:

$scope.controlOwnerObj.worker = $scope.controlOwners[0].worker;

Upvotes: 3

Related Questions