1

I have this data:

Continent":"Asia",
"Countries":{
            "Japan":[
                {
                    "Id":"1",
                    "ColumnName":"Osaka",
                    "Type":"Label", } ] }

I wanted to use the id and type as HTML tag attribute value like:

if label:

"<label> {{ColumnName}} </label>"

if textbox:

"<input type="text" value"Osaka">"

if dropdown:

"<select>
  <option value="Osaka">Osaka</option> </select>"

Is that possible?

Thanks for all the ideas you can share! :)

1 Answer 1

1

If the data is defined in your controller as

$scope.data = {
    "Continent":"Asia",
    "Countries":{
        "Japan":[
            {
                "Id":"1",
                "ColumnName":"Osaka",
                "Type":"Label", 
            }]
        }
    }

Then you can access these in your html like so:

<label>{{data.Countries.Japan[0].ColumnName}}</label>
<input type="text" ng-value"{{data.Countries.Japan[0].ColumnName}}">
<select>
    <option ng-value="{{data.Countries.Japan[0].ColumnName}}">{{data.Countries.Japan[0].ColumnName}}</option> 
</select>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for that webernado, but what if it's not always a dropdown? What if it can be a label, a textbox?
If you would like a list of labels or textboxes you can use ng-repeat to loop over the array of countries and display the ColumnName for each.

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.