[英]How to attach a vanilla JavaScript keyup listener to an angular md-autocomplete input using the dom id?
I have an angular md-autocomplete like this: 我有一个像这样的角度md-autocomplete:
<md-autocomplete md-input-id="myid" ...> </md-autocomplete>
And I want to do this: 我想这样做:
document.getElementById("myid") .addEventListener("keyup", function(event) { //my code } });
Where can I attach that event listener in my angular controller? 我可以在哪里将事件监听器附加到我的角度控制器中? I am using ui.router.
我正在使用ui.router。 It seems like each page isn't a real new page but just the dom updating.
似乎每个页面都不是真正的新页面,而只是dom更新。 So I think I need an event listener for when that render is complete so that I can access the element with the id.
所以我认为我需要一个事件侦听器来确定渲染何时完成,以便可以使用id来访问元素。
If you want to bind it to a key event, md-autocomplete has a property called md-search-text-change where you can attach a function on your scope. 如果要将其绑定到键事件,则md-autocomplete具有一个名为md-search-text-change的属性,您可以在该属性上附加作用域。
Here's an adapted example: https://plnkr.co/edit/Mih3sJTEiTjD2Qhresq6?p=preview 这是一个经过修改的示例: https : //plnkr.co/edit/Mih3sJTEiTjD2Qhresq6?p=preview
<md-autocomplete md-search-text-change="ctrl.searchTextChange(ctrl.searchText)"></md-autocomplete>
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.