How to fill select component programmatically


This is my question, How can i fill select component programmatically? for example i have some JSON data and need to add OPTION child to this tag.


You can use the AngularJS directive ng-repeat to go through your JSON data after you linked your data to a scope variable. If you use a service or something, the select can be updated automatically once it’s binded to the scope variable.

I made a small codepen to show you :
When you click the upper button, it adds one element to my JSON data and it’s automatically refreshed in the view.

I hope that’s what you were looking for.

1 Like

Well done, it works, and how can set SELECTED attribute for one of them.


I think that better is ng-options

maybe it’s harder to understand at the beginning but it’s more flexible and code is cleaner.

furthermore, select is not fine for mobile :wink: