1

I have this json object:

[{"@type":"XPickup","companyId":24,"companyCode":null}]

How do I read @type in my angularjs controller to display or modify it. I am unable to access it using:

$scope.object.@type // syntax error
$scope.object.type // undefined

Please tell me how do I access the @type key from my json object.

Thanks.

2 Answers 2

2

use $scope.load.loadStops[0]['@type'] or $scope.load.loadStops[0]["@type"]

Sign up to request clarification or add additional context in comments.

3 Comments

$scope.load.loadStops[0].["@type"] gives me syntax error
'@type' ie. (with single quotes) will not give you the error if it is sharing your code.
eclipse highlights the line to have errors with this: console.log($scope.load.loadStops[0].['@type']);
0

It will not work.. because @ is giving issue, remove @ then it will work..

$scope.data= [{"type":"XPickup","companyId":24,"companyCode":null}];
$scope.newData= $scope.data[0];

$scope.newData.type will access value

2 Comments

gives me syntax error: $scope.newData = $scope.load.loadStops[0]; $scope.newData.@type;
Actually I am getting @type from this json object: $scope.load; then $scope.load.loadStops; then $scope.load.loadStops[0].@type

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.