0

I need to call a service with returns a JSON array. But the array element name can contains several words.

example

 {"commerciele productnaam":"my product","looptijd in jaren":"0", etc... }

I am writing an angular controller which fetches the data, but I am unable to get the value of "commerciele productnaam".

<div ng-controller="PriceController as pc" ng-init="pc.getPrices()">
    <h1>Price from Pricing Service</h1>
    {{ pc.prices.msg.HOW TO ACCESS COMMERCIELE PRODUCTNAAM }} 

    <br/>
    <br/>
    MSG == {{ pc.prices.msg }} 
</div>

Is it possible to fetch the value via the variable name anyhow ?

1
  • 3
    use [] pc.prices.msg['HOW TO ACCESS COMMERCIELE PRODUCTNAAM'] notation that takes the property name string. Commented Feb 4, 2015 at 10:07

1 Answer 1

2

Use brackets instead:

<div ng-controller="PriceController as pc" ng-init="pc.getPrices()">
    <h1>Price from Pricing Service</h1>
    {{ pc.prices.msg['commerciele productnaam'] }} 

    <br/>
    <br/>
    MSG == {{ pc.prices.msg }} 
</div>

The bracket operator can be used instead of the dot operator to get object properties and you can use any string while the dot operator is more limited: no whitespaces, etc.

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

Comments

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.