当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Angular DOM modification timing

问题描述:

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 ?

网友答案:

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();

});

分享给朋友:
您可能感兴趣的文章:
随机阅读: