简体   繁体   中英

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.

<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. You can for exemple add (change)="aUselessMethod()" to your input and you will see that the code is working as expected.

Anyway I can't see a situation where you will need to get the input value like this.

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