admin管理员组文章数量:1389412
I am trying to get boolean value, if element id has been clicked in angular. I have tried to get boolean value through document.getElementById to find element clicked or not, but that is not working as expected.
This is how my sample html code:
<button id="my-btn-id" class="bx--number__control-btn up-icon">
If my button id will be clicked, I need to get true or need to return false. Here through click event I can able to get it, but I need to be identified through id. If any one have any idea please help me.
I am trying to get boolean value, if element id has been clicked in angular. I have tried to get boolean value through document.getElementById to find element clicked or not, but that is not working as expected.
This is how my sample html code:
<button id="my-btn-id" class="bx--number__control-btn up-icon">
If my button id will be clicked, I need to get true or need to return false. Here through click event I can able to get it, but I need to be identified through id. If any one have any idea please help me.
Share Improve this question edited Apr 22, 2019 at 14:31 Roy asked Apr 22, 2019 at 14:24 RoyRoy 9108 gold badges25 silver badges44 bronze badges 3- 1 If it is angular then go angular way...But in most cases you don't need id for such scenarios. If you could explain bit more about your issue then suggesting any answer would bee easier. – Jai Commented Apr 22, 2019 at 14:28
- isn't stopping the form submission would get it solved? Can you add your form sumission code also in your post? – Jai Commented Apr 22, 2019 at 14:44
- @Jai Yeah I got it...Through event listener I can get element id and problem resolved..Thanks – Roy Commented Apr 22, 2019 at 15:13
2 Answers
Reset to default 5Just a add a variable in your class, say: public myBtnIdClicked: boolean = false
<button id="my-btn-id" (click)="myBtnIdClicked = true" class="bx--number__control-btn up-icon">
Add a click listener on your button, set the variable myBtnIdClicked
to true once a click happens over the button.
This is probably not exactly what you want but why not keep it simple. I like simple.
controller
public clickedBtn1: boolean = false; // keep a number which is the same as button id.
Then you can always check by simply.
if (this.clickedBtn1)
{
//do something
// will only be reached if button has been clicked
}
template
<button id="1" class="bx--number__control-btn up-icon" (click)="clickedBtn1 = true">
本文标签: javascriptHow to get boolean valueIf element id clickedAngularStack Overflow
版权声明:本文标题:javascript - How to get boolean value, If element id clicked - Angular - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744633724a2616695.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论