admin管理员组文章数量:1418972
Hi I am trying to set value to a angular input box but when i do
let input = document.getElementById('mat-input-0');
input.value = "Something"
input box value changes on website but angular does not see any value when I try hit button and set form
Hi I am trying to set value to a angular input box but when i do
let input = document.getElementById('mat-input-0');
input.value = "Something"
input box value changes on website but angular does not see any value when I try hit button and set form
Share Improve this question edited Feb 16, 2021 at 14:12 Deitsch 2,22821 silver badges35 bronze badges asked Jun 5, 2019 at 10:10 Petr MPetr M 1633 gold badges3 silver badges13 bronze badges 7- 2 Because this isn't Angular, this is JS. Before using a framework, take some time, and RTFM ! – user4676340 Commented Jun 5, 2019 at 10:13
- That's not how you should approach things. Read the documentation. You'll want to use a model, and change the value of the model. angular.io/api/forms/NgModel – Tim VN Commented Jun 5, 2019 at 10:14
- It is not my project and I never used Angular before and I need to add some new features and I could not find answer to my question anywhere :( – Petr M Commented Jun 5, 2019 at 10:20
- The angular doc is a good place to start. If you need to work on a techno that you don't know it should be your first move. – JEY Commented Jun 5, 2019 at 10:28
- Yes you are right I just didn't want to read docs because it was minor change so I thought I will handle It without docs – Petr M Commented Jun 5, 2019 at 10:31
1 Answer
Reset to default 1You can bind to the input value property:
<input [value]="value">
or get the element in your TS file using @ViewChild
:
html:
TS:
@ViewChild('input', { static: false }) input: ElementRef;
AfterViewInit() {
// Change the value here
}
本文标签: javascriptHow to set value to angular inputStack Overflow
版权声明:本文标题:javascript - How to set value to angular input - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745298348a2652215.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论