Search code examples
angularjsangular-strap

AngularStrap parseOptions helper differs from AngularJS ngOptions parser


The AngularStrap (v2.2.4) parseOptions helper does not seem to work the way the AngularJS (v1.4.2) ngOptions parser works. I am not able to parse a string in AngularStrap which works fine in ngOptions.

This is the source data I wish to parse in AngularStrap is:

countryCodes = {
  "AF": "Afghanistan",
  "AX": "Aland Islands",
  "AL": "Albania",
  "DZ": "Algeria"
}

ngOptions parser will parse this string with no problems using this code in the ng-options directive:

k as v for (k,v) in countryCodes

The above string inside the html below works just fine:

<select ng-model="country" name="country" 
   ng-options="k as v for (k,v) in countryCodes" >    
</select>

Howevever, AngularStrap will not parse this string. The code below fails:

<button type="button" ng-model="country" bs-select class="btn btn-default"
    bs-options="k as v for (k,v) in countryCodes">
</button>

The AngularStrap documentation example uses a string format conforming to the ngOptions format in AngularJS, in particular the documentation uses

icon.value as icon.label for icon in icons

The format in the AngularStrap example attempts to parse an array of this format:

countryCodes = [
  {value: "AF",
   label: "Afghanistan"},
  {value: "AX",
   label: "Aland Islands"},
  {value: "AL",
   label: "Albania"},
  {value: "DZ",
   label: "Algeria"},
 ]

Looking at the AngularStrap parseOptions module on Github, it appears tehy are attempting to implement the same functionality found in AngularJS.

Am I doing something wrong, or does AngularStrap not parse objects for options?


Solution

  • AngularStrap document states it only supports array data source for options.

    "Available items are specified using the bs-options attribute. This attribute uses AngularJS ngOptions array data source syntax."