mui icon indicating copy to clipboard operation
mui copied to clipboard

How to use mui-select with AngularJS with dynamic data

Open gkimpson opened this issue 8 years ago • 6 comments

I am able to perfectly utilise the mui-dropdown using the code below, however when I try a similar approach with the mui-select option it doesn't generate correctly.

<mui-dropdown color="primary" label="Select a team" > <mui-dropdown-item ng-repeat="team in teams" link="#/link1">{{ team.name }}</mui-dropdown-item> </mui-dropdown>

I am trying to generate the select with the code below, but when I reload the page and click the select menu I only see one option (I am expecting 4) and it has {{option.label}} (note - the select is already opened by default - i do not want this to happen) <mui-select ng-model="rule.selectedAction" ng-options="team.name as label in teams" use-default> <mui-option value="{{ team.id }}" label="{{ team.name }}"></mui-option> </mui-select>

Please advise on my issue

gkimpson avatar Dec 07 '16 09:12 gkimpson

Hi @gkimpson - The MUI Select component doesn't support a list of options as an argument yet. Do you have time to take a stab at adding that functionality? The code is here: https://github.com/muicss/mui/blob/master/src/angular/select.js

amorey avatar Dec 07 '16 13:12 amorey

Ok I see - i'll have a go, although I am sure many others would need this so I am glad this ticket has been given a high priority.

gkimpson avatar Dec 07 '16 15:12 gkimpson

Glad to hear you want to have a go at it - it might require some advanced Angular knowledge but it should be an interesting problem to work on.

In terms of setting up the development environment, these instructions should work: https://github.com/muicss/mui#development-quickstart

There are some examples in the examples/angular/select.html file so you can add an options list example there: https://github.com/muicss/mui/blob/master/examples/angular/select.html

In case it helps, here's Angular's source code for ngOptions (hopefully we can come up with a simpler solution for MUI): https://github.com/angular/angular.js/blob/245b27101aad129061585252b73652054319ca82/src/ng/directive/ngOptions.js

Let me know if there's anything else I can do to help!

amorey avatar Dec 07 '16 15:12 amorey

@gkimpson I was just thinking about this problem. Have you tried using ng-repeat to add <mui-option> elements dynamically?

amorey avatar Dec 10 '16 20:12 amorey

@amorey Hi sorry for the delay, I tried ng-repeat initially but soon realised that wouldn't work and i'd need to make some amendments to MUI Select component in the core mui javascript file. If anybody does find a solution that would be brilliant!

gkimpson avatar Dec 20 '16 11:12 gkimpson

Interesting - what happened when you tried using ng-repeat? Do you have a branch with your changes? Let me know and I can merge it into the master.

amorey avatar Dec 21 '16 00:12 amorey