2

I am Using html input which gets changed via an External Js file. The input field is used to filter a list of table.

Very Basically I have: JavaScript

<script>
document.getElementById('search').value = returnCountry("China");
</script>

Html

<input type="text" id="search" ng-model="query">

So when the JavaScript is run it populates the input field but angular is not picking up that a change is being made and is not filtering. The filter works fine if you type or if you paste it in.

2 Answers2

0

try the following at the end of your javascript to force call the onChange event.

var event = document.createEvent("HTMLEvents");
event.initEvent("change",true,false);
document.getElementById("search").dispatchEvent(event)
Matt
  • 113
  • 4
  • 8
0

Why don't you do it the angularjs way and change the model and not the DOM. The DOM should just respond to changes in the model. Put at the start of your controller the following:

$scope.query = "China";

or whatever you return from the returnCountry function

$scope.query = returnCountry("China");

and you should be fine to go.

zszep
  • 4,450
  • 4
  • 38
  • 58