indrimuska / angular-selector

A native AngularJS directive that transform a simple <select> box into a full html select with typeahead.
http://indrimuska.github.io/angular-selector
MIT License
96 stars 36 forks source link

Refresh attribute added #16

Closed Nishchit14 closed 8 years ago

Nishchit14 commented 8 years ago

Refresh attribute added for fetch selector options by controller service directly,

Directive

<select selector
    model="browser"
    refresh = "vm.refresh(search,cb)"
    remote-param="search"
    options="browsers"
    label-attr="name">
</select>

In controller

vm.refresh = function (search, options) {

                MyAppService
                .getCountries({search:search})
                .success(function(countries){

                    if(countries && angular.isArray(countries)){

                            options(countries)
                    }

                })
            };

Here refresh function get first param as search text , which will used in service to get data and second param as callback options which will get service response as options for selector.

indrimuska commented 8 years ago

Hi @Nishchit14, I really like this feature but I cannot merge your PR it as-is, since your code is completely different from mine, you should respect my coding style (I mean, using TABS instead of spaces etc..), so that I can track changes and easily review your code.

Anyway, I like your plan of having an all-in-one "remote" property, as you said on gitter, used like this:

Also, I think that is better if remote/refresh function has only a search parameter and return a deferred object. What are your thought?

Nishchit14 commented 8 years ago

Thank you @indrimuska, I am very sorry for codding style, But it is auto formatting at commit time by IDE.

And just for advise, We should use jsHint or ESLint to maintain our codding standard, because every IDE has their own default style standard.

And i am agree with plan-2, All in one feature as remote attr and has only search parameter and return deferred object.

If you have green flag then i will do it in short time.

indrimuska commented 8 years ago

Yes, of course! Open another PR whenever you want! :)