country-regions / country-region-selector

Dynamic country and region dropdowns for your forms.
http://country-regions.github.io/country-region-selector/
MIT License
255 stars 115 forks source link

Not working #51

Open kumarsatish876 opened 7 years ago

kumarsatish876 commented 7 years ago

I have installed country-region-selector using below command

npm install country-region-selector --save

In my HTML I used it like this

<select  class="crs-country" data-region-id="ABC"></select>
<select id="ABC"></select>

but Countries are not showing in dropdown

benkeen commented 7 years ago

Hi @kumarsatish876 - did you include the library via a script tag in your page?

kumarsatish876 commented 7 years ago

Hi @benkeen I was trying to use it in my angular project. I had included the script in angular-cli.json file as

"scripts": [
        "../node_modules/country-region-selector/dist/crs.min.js",
        "../node_modules/country-region-selector/dist/crs.js"
      ]

Neither of them worked. I also tried jquery.crs.min.js file but did not work for me.

benkeen commented 7 years ago

Ah okay. Hmm... my hunch is that probably Angular is loading them async - or after the page has rendered. Take a look at this section: https://github.com/benkeen/country-region-selector#working-with-dynamic-html

You could maybe try calling crs.init() after you know that both the script has loaded and your DOM is ready with the two fields added.

The other possibility is that Angular is controlling the DOM and preventing the script automatically updating... I'm not sure, I'm afraid. My Angular is a bit rusty.

Either way, I think an Angular version of this script is needed. :)