I am trying to trigger an ng-change event programmatically from some javascript.
This is the element I am trying to trigger the ng-change event for
<select ng-model="user.siteId" name="siteSelect" ng-change="user.setSelectedSite(user.siteId)" class="ng-pristine ng-untouched ng-valid ng-empty">
<option value="" selected="selected">Please Select A Site</option>
<option id="siteOpts" value="1" ng-repeat="site in user.sites | orderBy:'siteName'" class="ng-binding ng-scope">Site1</option>
<option id="siteOpts" value="2" ng-repeat="site in user.sites | orderBy:'siteName'" class="ng-binding ng-scope">Site2</option>#
<option id="siteOpts" value="3" ng-repeat="site in user.sites | orderBy:'siteName'" class="ng-binding ng-scope">Site3</option>
</select>
I know I can select a value using this code
document.querySelector('.ng-pristine.ng-untouched.ng-valid.ng-empty').value = 2;
However this does not result in the ng-change event firing.
How can I select a value and ensure the ng-change event is fired?
user.siteId = 2insteaduserand add a propertysiteIdwith the value 2, e.g.$scope.user = {}; $scope.user.siteID = 2;