简体   繁体   English

来自模板引用输入的角度评估指令

[英]Angular evaluating directive from template referenced input

I would expect the simple code to result in the button being disabled until the text length is no longer less than 3. However it does not seem to evaluate correctly as it stays disabled regardless of the input. 我希望简单的代码会导致按钮被禁用,直到文本长度不小于3为止。但是,无论输入内容如何,​​它都保持禁用状态,因此似乎无法正确评估。

<input type="text" #myTextInput>
<button [disabled]="myTextInput.value.length < 3">Click me</button>

This code could work, but since no event are sent, angular is not trying to check any change on the page. 该代码可以工作,但是由于没有事件发送,Angular不会尝试检查页面上的任何更改。 You can for exemple add (change)="aUselessMethod()" to your input and you will see that the code is working as expected. 例如,您可以在输入中添加(change)=“ aUselessMethod()”,您将看到代码按预期运行。

Anyway I can't see a situation where you will need to get the input value like this. 无论如何,我看不到需要获取这样的输入值的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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