[英]Angular find element attribute doesn't work
我正在關注這篇簡單的文章: Arrow Keys to Navigate 。 這行底部有問題:
var nextInput = angular.element(angular.element.find('[arrow-keys-index="'+nextIndex+'"]'));
基本上,它需要做的是從我的 HTML 中找到一個元素,其中的屬性和值與字符串匹配,然后它可以調用以聚焦該元素。 HTML 它需要查找的示例如下所示:
<input type="text" arrow-keys-index="0:2" />
我在該行收到錯誤消息:
類型錯誤:angular.element.find 不是 HTMLInputElement 中的 function。 (arrow-keys-index.js:47:65) 在 defaultHandlerWrapper (angular.js:3795:11) 在 HTMLInputElement.eventHandler (angular.js:3783:9) 在 ZoneDelegate.invokeTask (zone-evergreen.js:406: 1) 在 Object.onInvokeTask (core.js:28564:1) 在 ZoneDelegate.invokeTask (zone-evergreen.js:405:1) 在 Zone.runTask (zone-evergreen.js:178:1) 在 ZoneTask.invokeTask [作為 invoke] (zone-evergreen.js:487:1) 在 invokeTask (zone-evergreen.js:1600:1) 在 HTMLInputElement.globalZoneAwareCallback (zone-evergreen.js:1626:1)
有什么想法嗎?
假設你的 nextIndex == "0:2"
將$element
注入 controller,然后:
var nextInput = $element.find('[arrow-keys-index="'+nextIndex+'"]');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.