gpt4 book ai didi

angularjs - 将事件绑定(bind)到链接函数中指令的子元素

转载 作者:行者123 更新时间:2023-12-02 23:35:21 26 4
gpt4 key购买 nike

我需要将一个事件绑定(bind)到指令的子级,该事件是在 templateUrl 中使用 ng-repeat 准备的。我正在尝试在 link 函数中绑定(bind)事件,但 children 还没有准备好。

这是plunker .

这里我想在使用 ng-repeat 准备的 li 标签上绑定(bind) click 事件。但是此时,link 是执行后,li 元素尚未准备好。

enter image description here

最佳答案

我已经用 Angular $timeout 解决了同样的问题

link: function (scope, element) {
$timeout(function () {
element.on('click', '#Id', function () {
console.log('inside event handler of the first child)
})
})
}

通过在指令中注入(inject) $timeout 来尝试此操作

关于angularjs - 将事件绑定(bind)到链接函数中指令的子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27656721/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com