0

I have a map data like following:

{
"RecipeID"   :"000682",
"RecipeName" :"My favaorite one",
"UpdateUser" :"Tek"
}

How should I convert map into form including label and text input, for example,

   Label (key)   :  Text Input(value)
 - RecipeID      :  _______________  
 - RecipeName    :  _______________
 - UpdateUser    :  _______________

I tried following method, but it seems fail.

<span ng-model="selectedRecipe">
  <form ng-repeat="items in selectedRecipe">
    <label>items[keys]</label>
    <input type="text" ng-model="items[values]"></input>
  </form>
</span>

1 Answer 1

1

Assuming selectedRecipe is Map<String,String>, and to workaround this issue, add a getter to access keys of your Map as Iterable:

get selectedRecipeKeys => selectedRecipe.keys;

And then, you can use it in ng-repeat this way:

<span ng-model="selectedRecipe">
  <form ng-repeat="key in selectedRecipeKeys">
    <label>{{key}}</label>
    <input type="text" ng-model="selectedRecipe[key]">
  </form>
</span>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, Mike. But it was still fail. Is this measure workable on your case ? Console show me: Class has no instance getter 'key'. NoSuchMethodError: method not found: 'key' Receiver: Instance of class Arguments: [] It seems that ng-repeat cannot recognize map data.
Sorry, I had no possibility to test the answer. Looks like there is an issue at angular's github, please see updated answer. Now it's working.

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.