简体   繁体   中英

angular.js - update `ng-model` with text.value

I have a javascript event to update input value dynamically

var posx = event.target.querySelector('input.posx');
          posx.value = event.dx;

Which it works to update the html :

<input type="text" ng-model="posx"  size="30" placeholder="x" class="post">

but somehow it did not update the ng-model="post . When I console.log($scope.posx); , I get

undefined

What seems to be the problem here

This code can be executed in Javascript context,

var e = document.getElementsByClassName('posx')[0];
var scope = angular.element(e).scope();
scope.posx = "updated value";
scope.$digest();

OR

var e = document.getElementsByClassName('posx')[0];
angular.element(e).triggerHandler('input');
$scope.posx = event.target.querySelector('input.posx');
          $scope.posx.value = event.dx;

try with $scope

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM