Angular DOM修改时序(Angular DOM modification timing)

编程入门 行业动态 更新时间:2024-10-23 11:18:21
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();

});

更多推荐

本文发布于:2023-07-25 19:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1265212.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时序   DOM   Angular   modification   timing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!