Angular DOM修改时序(Angular DOM modification timing)
我有一个控制器,可以在条形码扫描仪的"then"中更改一些值。
首先设置代码,然后设置"disabled"变量,然后聚焦输入。
.then(function (barcodeData) { // Success! Barcode data is here $scope.selectProdotto = barcodeData; $scope.txtDisabled = false; var pageElements = document.querySelectorAll('input[type=number], input[type=text], textarea'); var first_element = pageElements[1]; first_element.focus(); });我要关注的输入是;
<input class='input' type='number' ng-disabled="txtDisabled" />现在问题是我改变后输入仍然被禁用
$scope.txtDisabled = false;所以,当我做.focus()它会失败。
我的功能完成后,我的输入正确启用。
所以我问什么时候变量应用于DOM? 我如何等待输入准备好并启用焦点?
I have a Controller, that change some values in the "then" of a barcode scanner.
First thing it set the code, then set a "disabled" variable, and then focus an input.
.then(function (barcodeData) { // Success! Barcode data is here $scope.selectProdotto = barcodeData; $scope.txtDisabled = false; var pageElements = document.querySelectorAll('input[type=number], input[type=text], textarea'); var first_element = pageElements[1]; first_element.focus(); });The input that i want to focus is ;
<input class='input' type='number' ng-disabled="txtDisabled" />Now the problem is that the input is still disabled after i changed
$scope.txtDisabled = false;so when i do .focus() it fail.
After my function finish my input is correctly enabled.
So im asking when are variables applied to DOM ? How can i wait for the input to be ready and enabled to focus ?
最满意答案
你试过了吗
.then(function (barcodeData) { // Success! Barcode data is here $scope.selectProdotto = barcodeData; $scope.txtDisabled = false; $scope.$apply(); var pageElements = document.querySelectorAll('input[type=number], input[type=text], textarea'); var first_element = pageElements[1]; first_element.focus();});
did you try
.then(function (barcodeData) { // Success! Barcode data is here $scope.selectProdotto = barcodeData; $scope.txtDisabled = false; $scope.$apply(); var pageElements = document.querySelectorAll('input[type=number], input[type=text], textarea'); var first_element = pageElements[1]; first_element.focus();});
更多推荐
发布评论