L
L
Lexasq2015-11-11 12:06:08
JavaScript
Lexasq, 2015-11-11 12:06:08

How to work with dynamically added ng-change?

There are dynamically added selects with efforts inside, a flag hangs on each country and I use ng-change to pull it out as a background, because it is not friendly with block elements inside itself. For the first select, ng-change="update()" works, but not for dynamically added ones, what's the problem?

<select class="language"  ng-model="selectedItem" ng-change="update()" >
                          <option value="">---Please select---</option>
                          <option ng-repeat="language in languages" style="background-image: url(img/{{language.id}}" >
                            {{language.called}}
                          </option>
                        </select>

$scope.update = function (){
   
    img_str=$scope.selectedItem;
    img_str="url(img/"+ img_str+"_flag.jpg)";
    angular.element(document.querySelector(".native select")).css("background-image", img_str);
    console.log(img_str);
  }});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lega, 2015-11-11
@lega

You need to add value attribute to dynamic options

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question